Learn about Windows PowerShell
Summary: Learn to create a Windows PowerShell hash table.
How can I create an empty hash table?
Use @{} and assign it to a variable:
$hash = @{}
hi ed,
here another variant:
PS II> $ht=New-Object Hashtable
PS II> $ht.GetType()
To create more than one:
@{} | sv hash1,hash2,hash3,hash4
Now you have 4 of them: $hash1, $hash2, $hash3, and $hash4.
Create and empty ordered hash table
#requires -version 3
$h=[ordered]@{}
@mjolinor & @Doug Finke
---> this is a great suggestion, thanks for sharing.
I can not test with ps3, are that this works ?
PS III> [ordered]@{} | sv hash1,hash2,hash3,hash
sorry for my english
@Walid It does indeed.
PS C:\> [ordered]@{}|sv hash1,hash2,has3,hash4
PS C:\>
PS C:\> $hash2.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True OrderedDictionary System.Object
Always, helpful.
Also folks, depending on your font, be careful about these 2 declarations:
@()
@{}
I've just about torn my hair out on a script when I accidentally declared an array instead of a hashtable...