Collections:
Other Resources:
Hashtable in Windows PowerShell Scripts
What is a hashtables of objects in Windows PowerShell scripts?
✍: FYIcenter.com
A hashtables in Windows PowerShell is a data structure where
pieces of data are stored in the structure as key-value members.
The value of a member represents the data,
and the key of a member provides a name for the data.
Hashtable keys must be unique strings. While hashtable values can be any types of data.
You can create a hashtable by listing objects using the @{...}syntax as shown below:
@{key1=value1;key2=value2;key3=value3;...}
For example, the following script creates a hashtable of 3 members and assign it to variable $p:
$p = @{"FirstName"="John";"LastName"="Smith";"Age"=40}
"My profile:"
$p
New key-value pairs can also be added to a hashtable using the Add() method:
$p = @{"FirstName"="John";"LastName"="Smith";"Age"=40}
$p.Add("Email","john@smith.com")
"My profile:"
$p
You can access a member value of a hashtable with its key using the "." operation as shown below:
$p = @{FirstName="John";LastName="Smith";Age=40}
"My profile:"
" First Name: "+$p.FirstName
" Last Name: "+$p.LastName
" Age: "+$p.Age
You can also access a member value of a hashtable with its key using the "Item()" method:
$p = @{FirstName="John";LastName="Smith";Age=40}
"My profile:"
" First Name: "+$p.Item("FirstName")
" Last Name: "+$p.Item("LastName")
" Age: "+$p.Item("Age")
⇒ Loop Hashtable Members in Windows PowerShell Scripts
⇐ Loop Array Elements in Windows PowerShell Scripts
2016-10-29, ∼2668🔥, 0💬
Popular Posts:
How do I install simplified and traditional Chinese language packs on my Windows XP system? Installi...
Where to find tutorials on using Windows 7 Security? Here is a collection of tutorials on Windows 7 ...
What is "Protexis Licensing V2" in my Windows 7 service list? And how is "Protexis Licensing V2" ser...
How to view system properties on Windows Server 2012? I just want to get some basic information abou...
Can I remove startup application "RealPlay.exe - RealPlayer Tray Bar Application" to speedup my comp...