Don’t do that: An empty hashtable is created and then the elements are added.
1 2 3 4 5 6 7 |
$hashtable = @{} $hashtable.Add('User1','Department1') $hashtable.Add('User2','Department2') $hashtable.Add('User3','Department3') $hashtable.Add('User4','Department4') $hashtable.Add('User5','Department5') |
Do that: In this scenario, I prefer to create the hashtable with the elements (key/value), not after the creation: it’s faster and more practical.
1 2 3 4 5 6 7 |
$hashtable = [ordered]@{ User1 = 'Department1' User2 = 'Department2' User3 = 'Department3' User4 = 'Department4' User5 = 'Department5' } |
Note: The attribute “ordered” is optional (it exists since Powershell v3 and creates an ordered dictionary).