Using MemberSets

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

In a previous tip you learned how PropertySets can create groups of properties for easier access. Yet another (hidden) feature of PowerShell objects is MemberSets. Objects can contain a MemberSet called PSStandardMembers which normally is hidden (along with a number of other MemberSets):

PS> Get-Process | Get-Member -MemberType MemberSet
PS> Get-Process | Get-Member -MemberType MemberSet -Force

   TypeName: System.Diagnostics.Process

Name              MemberType Definition
----              ---------- ----------
psadapted         MemberSet  psadapted {BasePriority, ExitCode, HasExited, ExitTime, H...
psbase            MemberSet  psbase {BasePriority, ExitCode, HasExited, ExitTime, Hand...
psextended        MemberSet  psextended {__NounName, Name, Handles, VM, WS, PM, NPM, P...
psobject          MemberSet  psobject {BaseObject, Members, Properties, Methods, Immed...
PSStandardMembers MemberSet  PSStandardMembers {DefaultDisplayPropertySet}

PSStandardMembers controls the standard fallback properties that PowerShell displays. This line lists the default properties for service objects returned by Get-Service:

PS> Get-Service | Select-Object -First 1 |
ForEach-Object { $_.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames } Status Name DisplayName

Twitter This Tip! ReTweet this Tip!


Posted Jan 25 2013, 06:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.