PoshCode Archive  Artifact Content

Artifact 3c8753f4992ddb0eba6b85c6f722455f2ce1ae0ad4b457af107148fc1c99d97b:

  • File h20-Hashtables-2-object.ps1 — part of check-in [9ef0d2dd60] at 2018-06-10 13:14:33 on branch trunk — hashtable to object function. (user: nQPuDDji size: 1059)

# encoding: ascii
# api: powershell
# title: h20 -Hashtables 2 object
# description: hashtable to object function.
# version: 0.1
# type: function
# author: nQPuDDji
# license: CC0
# x-poshcode-id: 2697
# x-archived: 2016-05-19T15:22:19
# x-published: 2012-05-27T11:44:00
#
# 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 | % { New-Object PSObject -Property $_ }
                    }  
                }
            
 end{}
}