Displaying the properties of an variable

Brass Contributor

Hi

 

I created a variable of type String.

How do I display all of its properties?

 

Thanks

 

Bye

3 Replies

@balubeto 

 

The most appropriate way is:

 

Get-Member -InputObject $YourStringVariable;

 

An acceptable alternative - though it does misrepresent situations where collections are involved - is:

 

$MyStringVariable | Get-Member;

 

The convenience alias for Get-Member is typically "gm".

 

 

Cheers,

Lain

@LainRobertson 

 

I noticed a peculiarity:

 

Even if I write one of the above two instructions at the beginning of a script, its ouptut is only displayed at the end of that script. How come?

 

Note: I am using Visual Studio Code as my IDE.

 

Thanks

 

Bye

@balubeto 

 

That's quite common as the pipeline is written asynchronously to the output stream.

 

You can generally force the issue using Out-Default but I wouldn't recommend doing this outside of test scenario (where I'd advocate for using other mechanics such as Write-Warning or Write-Verbose instead.)

 

Example:

Get-Member -InputObject $YourStringVariable | Out-Default;

 

Cheers,

Lain