PoshCode Archive  Artifact [4b9817013b]

Artifact 4b9817013b920fa1b835a540f7e7f094c5f58cf7830968adcb4b70675f2be0cf:

  • File h20-Hashtables-2-object.ps1 — part of check-in [a063be42c1] at 2018-06-10 13:08:44 on branch trunk — hashtable to object function. (user: karl prosser size: 1084)

# 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{}
}