Guy recommends :
Free SolarWinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



Windows PowerShell 3.0 Hash Tables

PowerShell 3.0 [Ordered] Hash Table

What's new with hash tables in PowerShell 3.0 is they can be[Ordered].  With just one command you can sequence values thus: [Ordered]@{"Key1" = "Value 1";"Key2" = "Value 2; etc ..."}.

 ♦

Hash Table Refresher

Arrays are useful, but only if you have a series of single values.  Hash tables extend arrays by allowing you to have data in the format of Key = Value.

$Countries = @{"Wales" = "Daffodil"; "England" = "Rose"; "Scotland" = "Thistle"; "Ireland" = "Shamrock"}
$Countries

Note 1:  Observe the semi-colon; between each pair.

Note 2:  If need be, you could display just the Keys with $Countries.Keys. 

Note 3:  Speech marks are only required if the key, or its value, contains a space.

PowerShell 3.0 [Ordered] Command

The new feature of PowerShell v 3.0 hash tables is that you can sort the key using the [Ordered] command see this example:

Clear-host
$Countries = [Ordered]@{"Wales" = "Daffodil"; "England" = "Rose"; "Scotland" = "Thistle"; "Ireland" = "Shamrock"}
$Countries

This [Ordered] method sorts on the value, e.g.,  Daffodil, Rose, Shamrock and Thistle.

Alternatively, you can use the old .GetEnumerator() method to sort on Name.

Clear-Host
$Countries = [ordered]@{"Wales" = "Daffodil"; "England" = "Rose"; "Scotland" = "Thistle"; "Ireland" = "Shamrock"}
$Countries. GetEnumerator() | Sort-Object Name

Hash Table Results

Name Value
---------  -----
England  Rose
Ireland   Shamrock
Scotland Thistle
Wales     Daffodil

Guy Recommends:  SolarWinds' Free Bulk Import ToolFree Download of Solarwinds  Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD's attributes, click to import the users.  Optionally, you can provide the name of the OU where the new accounts will be born.

There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

Further Research of PowerShell's Hash Tables

Hashtables are sometimes called dictionaries; whatever the name, and whatever the spelling, you can list the full set of methods and properties by appending | Get-Member.

$Countries = @{"Wales" = "Daffodil"; "England" = "Rose"; "Scotland = "Thistle"; "Ireland" = "Shamrock"}
$Countries | Get-Member

One benefit of creating a hash table is that you can add data, for example:

$Countries.Add("France", "Cockrell")

Note 4: The .Add method requires (Parenthesis) not {curly} brackets.

Footnote: This research solves the mystery of why PowerShell doesn't have a .Delete method; the reason is because it consistently uses .Remove for this task.

Summary of PowerShell v 3.0 Ordered Hash Table

Another new feature in version 3.0 is [Ordered] hash tables.  Thanks to this one word [ordered] you can achieve a quicker and better solution for sequencing values than was possible in PowerShell v 2.0.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell v 3.0 examples

PowerShell Tutorials  • What's New in PowerShell 3.0  • PowerShell v 3.0 ISE

PowerShell 3.0  • Disable-NetAdapter  • Disable-NetAdapter  • Enable-NetAdapter

PowerShell Network Cmdlets  • PowerShell 3.0 Logon Script  • PowerShell Show-Command

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, SolarWinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2012 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: