June 22, 2021
Beautiful day, of course now I look like a lobster with a farmer’s tan.
http://raygoble.info/wp-content/uploads/2021/06/5581.mp4
June 22, 2021
Beautiful day, of course now I look like a lobster with a farmer’s tan.
http://raygoble.info/wp-content/uploads/2021/06/5581.mp4
Have you thought about how many PowerShell functions seem to only return a subset of the returned object’s properties, while there are many more returned properties that are present but just not displayed? Of course, you can display them all by piping the output through “Select-Object *”, but by default not all properties are displayed.
Ever wonder how to do that in your own functions? Below is a method of achieving that result.
#Run these three lines sometime before the creation of the output object, specifying the fields to include in the DefaultDisplayPropertySet:
[string[]]$visible = ‘ComputerName’,’Domain’,’Manager’
$Type = ‘DefaultDisplayPropertySet’
[Management.Automation.PSMemberInfo[]]$Config = New-Object System.Management.Automation.PSPropertySet($Type,$Visible)
ForEach($Result in $ResultSet){
$ThisObject = [PSCustomObject]@{
ComputerName = $Result.ComputerName
IPAddress = $Result.IPAddress
Domain = $Result.Domain
Manager = $Result.Manager
Function = $Result.Function
}
#Now add this next line to apply the DefaultDisplayPropertySet to the output object:
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $Config -InputObject $ThisObject
$OutObject.Add(($ThisObject)) | Out-Null
}
$OutObject
Recent Posts