Powershell How to Use Dictionary/Hash Table

Dictionary/Hash Table is a "Key, Value" pair. It can make a list of key and value. So its very easy to relate which key belongs to which value. Below is the example of hash table.

clear
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell 
$SiteUrl = "http://pps-dd-lite:9595/Sites/IPM"
$LobSystemInstance = "IPM.BCS.ReferenceDataInstance"
$EntityNamespace = "IPM.BCS.ReferenceData"
$myHash = @{}
$myHash["Key_1"] = "Value_1_ABC"
$myHash["Key_2"] = "Value_2_DEF"
$myHash["Key_3"] = "Value_3_GHI

foreach($key in $($myHash.keys))
{
 Write-Host "For key"  $key  " value is "  $myHash[$key]
}
 
Result:



Comments

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell