COLLECTIONS
DICTIONARIES AND HASHTABLES
Creating and inspecting hashtables
$user = @{ FirstName = "John"; LastName = "Smith"; PhoneNumber = "555-1212" }
Enumerating hashtable
$h = @{a=1; b=2; c=3}
foreach ($pair in $h.GetEnumerator())
{
$pair.key + " is " + $pair.value
}
Modifying and manipulating hashtables
$user = @{ FirstName = "John"; LastName = "Smith"; PhoneNumber = "555-1212" }
$user.date = get-date
$user["city"] = "Seattle"
$user.remove("city")
$newHashTable = @{}
$newHashTable
$newHashTable.one =1
$newHashTable.two = 2
ARRAYS AND SEQUENCES
Instead of having array literals, there’s a set of operations that create collections as needed. In fact, collections of objects are created and discarded transparently throughout PowerShell. If you need an array, one will be created for you. If you need a singleton (or scalar) value, the collection will be unwrapped as needed.