Object Magic (Part 2)

by Oct 23, 2019

Via the secret “PSObject” property, you can get detailed information about object members. For example, if you’d like to know which object properties can actually be changed, try this:

# get any object
$object = Get-Process -Id $pid

# try and access the PSObject
$object.PSObject.Properties.Where{$_.IsSettable}.Name

The result is a list of properties in Process objects that can be assigned new values:

 
MaxWorkingSet
MinWorkingSet
PriorityBoostEnabled
PriorityClass
ProcessorAffinity
StartInfo
SynchronizingObject
EnableRaisingEvents
Site 
 

Likewise, you can easily figure out all properties that currently have no value (are empty):

# get any object
$object = Get-Process -Id $pid

# try and access the PSObject
$object.PSObject.Properties.Where{$null -eq $_.Value}.Name  

Twitter This Tip! ReTweet this Tip!