Powershell Hash and Arrays

Two ways of making a table of hash tables and arrays.

[codesyntax lang=”powershell”]

#Alt1
$Array = New-Object System.Collections.ArrayList
#Foreach ()
{
	$Hash = New-Object -TypeName PSObject -Property @{
	    Status = "Ok"
	    DisplayName = "Test"
	    	    
	}
$Array.Add($Hash) | Out-Null
Remove-Variable $Hash -ErrorAction SilentlyContinue
#} 
$Array | Out-GridView


#Alt2
$Array = New-Object System.Collections.ArrayList
$Hash = New-Object PSObject
#Foreach ()
#{
$Hash | Add-Member -NotePropertyName "Status" -NotePropertyValue "Ok"
$Hash | Add-Member -NotePropertyName "DisplayName" -NotePropertyValue "Test"
$Array.Add($Hash)
Remove-Variable Has -ErrorAction SilentlyContinue
#}

$Hash | Out-GridView

[/codesyntax]

This entry was posted in Powershell. Bookmark the permalink.