Last active
August 29, 2015 14:24
-
-
Save JohnRoos/f8d8fbe68504cd2d4cec to your computer and use it in GitHub Desktop.
Xpression class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Xpression | |
{ | |
[string]$Name | |
[scriptblock]$Expression | |
[hashtable] getExpression() { | |
return @{ Name = $this.Name; Expression = $this.Expression } | |
} | |
} | |
class XpressionArray | |
{ | |
[Xpression[]]$Expression | |
[array] Get() { | |
return $this.Expression.getExpression() | |
} | |
Add([string]$n, [scriptblock]$x) { | |
$temp = New-Object -TypeName Xpression | |
$temp.Name = $n | |
$temp.Expression = $x | |
$this.Expression += $temp | |
} | |
Add([string]$n) { | |
$temp = New-Object -TypeName Xpression | |
$temp.Name = $n | |
$temp.Expression = [Scriptblock]::Create('$_.' + $n ) | |
$this.Expression += $temp | |
} | |
} | |
# How to use it | |
$exp = New-Object -TypeName XpressionArray | |
$exp.Add('Name') | |
$exp.Add('Id') | |
$exp.Add('KB',{ $_.WorkingSet / 1Kb }) | |
$exp.Add('MB',{ $_.WorkingSet / 1Mb }) | |
Get-Process -Name powershell* |select $exp.Get() | Format-Table | |
Get-Process -Name powershell* |select $exp.Get() | Get-Member |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment