PowerShell

PowerShell: Show hidden properties from an Object

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' 

}

Anmerkung 2020-07-28 085113

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

Anmerkung 2020-07-28 094039

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.

Anmerkung 2020-07-28 085803

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

Anmerkung 2020-07-28 093819

Categories: PowerShell

Tagged as: ,

4 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.