PoshCode Archive  Artifact [e19f9ac44a]

Artifact e19f9ac44aebd1406a0b37bda2e3108700d820c912a7f6ed5350147f572687a1:

  • File AS-function.ps1 — part of check-in [de7046db33] at 2018-06-10 12:56:16 on branch trunk — AS function. simple wrapper for generating the hashtables that select-object uses (user: karl prosser size: 1005)

# encoding: ascii
# api: powershell
# title: AS function
# description: AS function. simple wrapper for generating the hashtables that select-object uses
# version: 0.1
# type: function
# author: karl prosser
# license: CC0
# function: new-selectexpression
# x-poshcode-id: 1019
# x-archived: 2012-04-24T13:15:42
# x-published: 2009-04-13T14:59:00
#
#
#region setup AS function
function new-selectexpression
{
if ($args.count -eq 1) { $theargs = $args[0] } else {$theargs= $args }
if ($theargs.count -gt 1)
{
for($loop=0;$loop -lt ($theargs.count-1);$loop+=2)
 { 
  @{Name=$theargs[$loop];Expression=$theargs[$loop+1]} 
 }
}
if (!($theargs.count % 2) -eq 0) {@{Name=$input[$input.count-1];Expression= invoke-Expression "{}" } }
}
set-Alias as  new-selectexpression
#endregion
#Examples
#Select (as theprocess ,name , 
#            "CPU" , {$_.privatememorysize/ 1KB} , 
#			"memory KB" , {$_.privatememorysize/ 1KB} , 
#			"peak KB",  {$_.peakworkingset /1KB} ) -first 2