Datasheet

30 CHAPTER 1
WINDOWS POWERSHELL 101
Hash tables, also known as dictionaries, are declared by wrapping the list of semico-
lon-separated items in curly braces and de ning a “key” for each item by setting the
key equal to the value:
PS C:\> $sites = @{“Portal” = “http://portal”; i
“Team Sites” = “http://teams”}
PS C:\> $sites
Name Value
---- -----
Portal http://portal
Team Sites http://teams
PS C:\>
e quotation marks around the key portion are only necessary if the name has a
space in it. However, its generally a good practice always to wrap string names in
quotes (note that either the key or the value can be any object type and do not have
to be strings).
Like arrays, hash tables can easily be combined:
PS C:\> $sites1 = @{“Portal” = “http://portal”; i
“Team Sites” = “http://teams”}
PS C:\> $sites2 = @{“My Sites” = “http://mysites”; i
“Project Sites” = “http://projects”}
PS C:\> $sites1 += $sites2
PS C:\> $sites1
Name Value
---- -----
Project Sites http://projects
Portal http://portal
My Sites http://mysites
Team Sites http://teams
PS C:\>
Individual items in the hash table can then be accessed either using dot notation
(thanks to the dictionary adapter) or by wrapping the key name in square brackets
and appending to the variable:
c01.indd 30c01.indd 30 5/16/2011 11:12:34 AM5/16/2011 11:12:34 AM