Created
September 6, 2022 23:45
-
-
Save santisq/43b32da93947da457b552a604b066c21 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