# encoding: ascii # api: powershell # title: h20 -Hashtables 2 object # description: hashtable to object function. # version: 0.1 # type: function # author: karl prosser # license: CC0 # x-poshcode-id: 2325 # x-derived-from-id: 2335 # x-archived: 2010-10-30T04:58:41 # # used to be able to make custom objects with math inside the pipeline # #hashtable to object function. #used to be able to make custom objects with math inside the pipeline #e.g. 1..10 | h20 { @{karl = $_;dude = $_+1} } #gps | h20 { @{name = $_.processname; mem = $_.workingset / 1MB} } function h20([scriptblock]$sb ) { begin {} process{ if ($sb -ne $null) { $ht = &$sb; if ($ht -is [hashtable]) { New-Object PSObject -Property $ht} } if ($ht -is [object[]]) { $ht | where { $_ -is [hashtable]} | % { New-Object PSObject -Property $_ } } } end{} }