Forum Discussion
Displaying the properties of an variable
Hi
I created a variable of type String.
How do I display all of its properties?
Thanks
Bye
3 Replies
- LainRobertsonSilver Contributor
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
- balubetoBrass Contributor
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
- LainRobertsonSilver Contributor
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