-
-
Save kevinblumenfeld/9a78ceeb50ee36421ee457d2e0092a99 to your computer and use it in GitHub Desktop.
sets PSStandardMember for all input objects
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
using namespace System.Management.Automation | |
function Set-StandardMember { | |
[CmdletBinding()] | |
param( | |
[parameter(Mandatory, ValueFromPipeline)] | |
[object] $InputObject, | |
[parameter(Mandatory)] | |
[string[]] $DefaultProperties | |
) | |
begin { | |
[PSMemberInfo[]] $info = [PSPropertySet]::new('DefaultDisplayPropertySet', $DefaultProperties) | |
$memberSet = [PSMemberSet]::new('PSStandardMembers', $info) | |
} | |
process { | |
$InputObject.PSObject.Members.Add($memberSet) | |
$InputObject | |
} | |
} | |
$InputObject = [pscustomobject]@{ | |
foo = 123 | |
bar = 456 | |
} | |
$InputObject | Set-StandardMember -DefaultProperties foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment