You may ask yourself how it comes that you apparently can do something in PowerShell without finding an attribute or method for this. You are investigating all methods and attributes of your object , but you find nothing that looks like what you are looking for. The reason for this is that there exists hidden properties.
In this blog post I will show you how you can display these hidden properties and give you some useful examples to play with.
Showing Hidden Properties
You can display all properties by using the -Force parameter of the Get-Member cmdlet.
Take the code below as an example. It’s a hashtable containg objects (key – value pairs).
### Creating Hash-Table Object $a = @{ Name = 'Patrick' Gender = 'Male' Age = '33' }
We now have learned that Get-Member -Force shows much more properties than Get-Member only.
You can now display all propertes (including hidden) with the -Force parameter.
$a | Get-Member -Force
Some of them are particularly interesting, because when using them you can get even more out of objects.
For example, you can retrieve only keys or values or you can simply get the object classes.
Here are some examples for a better understanding of the topic.
### Creating Hash-Table Object $a = @{ Name = 'Patrick' Gender = 'Male' Age = '33' } ### Having fun with hidden properties $a.pstypenames $a.psadapted $a.psobject $a.psobject.BaseObject.Keys $a.psobject.BaseObject.Values $a.count
Fine. That is all I wanted to share today.
See also
You may also want to take a quick glance at the -View parameter which is described here: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-member?view=powershell-7
Categories: PowerShell
useful codes, thanks for the article!
LikeLiked by 1 person
Thank you
LikeLike