Hashtables (Associative Arrays)

Hashtable Definitions

PowerShell hashtables (also called associative arrays) allow you to associate keys with values. To define a hashtable, use the syntax:

$myHashtable = @{}

You can initialize a hashtable with its key/value pairs when you create it. PowerShell assumes that the keys are strings, but the values may be any datatype.

$myHashtable = @{ Key1 = "Value1"; "Key 2" = 1,2,3 }

Hashtable Access

To access or modify a specific element in an associative array, you may use either the array-access or property-access syntax:

$myHashtable["Key1"]

Returns "Value1".

$myHashtable."Key 2"

Returns the array 1,2,3.

$myHashtable["New Item"] = 5

Adds "New Item" to the hashtable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.136.165