-
-
Save aldrichtr/2ea4ff2be0b352067fe14073ec31defa to your computer and use it in GitHub Desktop.
sets PSStandardMember for all input objects
This file contains 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