Learn how to discover all of a PowerShell object’s properties and see their values.
Object properties tell us about the object
Every time you run a “Get-” PowerShell cmdlet, you receive a single object or set of objects. In the programming world, an object’s properties are attributes about the object itself. A property could be a text string, a number, a timestamp, or any other descriptive value. Each property has a name and a corresponding value (and that value could potentially be null).
Not all properties displayed by default
Depending on the object type, not all of a object’s properties are displayed when you run the “Get-” cmdlet and display the output. If the output uses Format-Table, trying to squeeze all of the properties into the table could make the output noisy and unreadable, so it makes sense that some properties are excluded. However even if you use Format-List, some properties may still not be shown by default.
For demonstration, we’ll run Get-Service for the Windows Defender service and look at the default output.
PS C:\Users\aaron> Get-Service -Name WinDefend Status Name DisplayName ------ ---- ----------- Stopped WinDefend Windows Defender Service
Note that only three properties are displayed: Status, Name, and DisplayName. Are those the only properties of the object? Let’s format the output using Format-List.
PS C:\Users\aaron> Get-Service -Name WinDefend | Format-List Name : WinDefend DisplayName : Windows Defender Service Status : Stopped DependentServices : {} ServicesDependedOn : {RpcSs} CanPauseAndContinue : False CanShutdown : False CanStop : False ServiceType : Win32OwnProcess
Now nine properties are displayed; six more than the default output! That must be all of the properties then, right? How can we tell for sure?
Use Get-Member to see an object’s properties and methods
The Get-Member cmdlet is used to definitively show us a PowerShell object’s defined properties and methods. We use it by piping the output from our Get-Service cmdlet into Get-Member. Note in the sample output below the TypeName value at the top: System.ServiceProcess.ServiceController. This Type is actually a .NET class. If you do a web search for the TypeName, one of your first search results will be this MSDN documentation page. You can match up the Properties and Methods listed in the output below with the MSDN documentation, which includes additional descriptive text about each property and method.
PS C:\Users\aaron> Get-Service -Name WinDefend | Get-Member TypeName: System.ServiceProcess.ServiceController Name MemberType Definition ---- ---------- ---------- Name AliasProperty Name = ServiceName RequiredServices AliasProperty RequiredServices = ServicesDependedOn Disposed Event System.EventHandler Disposed(System.Object, System.EventArgs) Close Method void Close() Continue Method void Continue() CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType) Dispose Method void Dispose(), void IDisposable.Dispose() Equals Method bool Equals(System.Object obj) ExecuteCommand Method void ExecuteCommand(int command) GetHashCode Method int GetHashCode() GetLifetimeService Method System.Object GetLifetimeService() GetType Method type GetType() InitializeLifetimeService Method System.Object InitializeLifetimeService() Pause Method void Pause() Refresh Method void Refresh() Start Method void Start(), void Start(string[] args) Stop Method void Stop() WaitForStatus Method void WaitForStatus(System.ServiceProcess.ServiceControllerStatus desiredStatus), void WaitForStatus(System.ServiceProcess.ServiceControllerStatus desiredStatus, timespan tim... CanPauseAndContinue Property bool CanPauseAndContinue {get;} CanShutdown Property bool CanShutdown {get;} CanStop Property bool CanStop {get;} Container Property System.ComponentModel.IContainer Container {get;} DependentServices Property System.ServiceProcess.ServiceController[] DependentServices {get;} DisplayName Property string DisplayName {get;set;} MachineName Property string MachineName {get;set;} ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;} ServiceName Property string ServiceName {get;set;} ServicesDependedOn Property System.ServiceProcess.ServiceController[] ServicesDependedOn {get;} ServiceType Property System.ServiceProcess.ServiceType ServiceType {get;} Site Property System.ComponentModel.ISite Site {get;set;} StartType Property System.ServiceProcess.ServiceStartMode StartType {get;} Status Property System.ServiceProcess.ServiceControllerStatus Status {get;} ToString ScriptMethod System.Object ToString();
Display all PowerShell object’s properties in output
From the Get-Member output, we learn there are fourteen properties and two alias properties of the System.ServiceProcess.ServiceController object type. However if you recall, when we used Format-List to display the output, we were only shown nine properties. To display ALL of the properties, we need to use the -Property parameter with a wildcard value. You see below sixteen properties are displayed, even if they have null values. This approach is helpful when you exploring results and are looking for properties of interest. Get-Member and MSDN documentation may give you an idea of what properties are helpful to you, but interrogating a sample object directly using -Property * will help you validate that a property has the information you need.
PS C:\Users\aaron> Get-Service -Name WinDefend | Format-List -Property * Name : WinDefend RequiredServices : {RpcSs} CanPauseAndContinue : False CanShutdown : False CanStop : False DisplayName : Windows Defender Service DependentServices : {} MachineName : . ServiceName : WinDefend ServicesDependedOn : {RpcSs} ServiceHandle : Status : Stopped ServiceType : Win32OwnProcess StartType : Manual Site : Container :
Carsten Giese says
here is a way to get the details of each property:
$object = Get-Process | select -first 3
foreach ($x in $object | get-member) {
if ($x.MemberType -eq “Property” -and $x.Name -notlike “__*”) {
write-host “`nName :” $x.Name
write-host “Type :” $x.Definition.Split(” “)[0]
write-host “Count:” $object.$($x.Name).count
write-host “Value:” $object.$($x.Name)
}
}
Garrett Michael Hayes says
Even the get-member doesn’t seem to automatically display all the properties.
I found that adding a wildcard for the properties filter gets you the full list.
For example, compare:
get-aduser Joe.Snuffy | get-member
with
get-aduser Joe.Snuffy -properties * | get-member
Powershell_Padawan says
This is ALL good to know, thanks.
Tried to re-work the Get-Member to get full property list, to see if this could show all 16 properties, like Garrett’s, but couldn’t make it work. (Name & RequiredServices Properties not visible unless piping Get-Service to Format-List with wildcard (gsv *defend* | fl -Property *)
Trying to measure these, I noticed something (probably a good reason for)
count / measure reports 14 (of expected 16) on
PS> gsv *defend | FL Property *
Count : 14
I try to count the number of results SEEN with -fl, count reports 5 (not 14)
gsv *defend* | fl -Property * | measure
Is there a reason for this, and a command to count results in PS, eg 14, or even 16 ?
Thunks and Thanks!
Ramiro says
Nice content! Very well explained, specially for PS beginners like me =)
Tester says
| Select-Object *
also works.
Haniel Croitoru says
Hi Aaron,
I’m looking for some advice around getting further information about objects that are nested. Here’s my scenario. I’m running a script to retrieve all items in a SharePoint site. Some of the items contain properties that are objects themselves or list of values. I need a way to detect what type of an object it is and then get the content of it.
I tried using the Get-Member and look at the Definition property, but that seems more of a hack. Any idea how to convert members into their own objects to retrieve their members? I know that they have data as the entire object is getting loaded from a JSON file.
Thanks,
-Haniel
John Trovato says
For custom objects:
$obj.Psobject.Properties.name # <- Property names