Nov 15 2022 09:45 AM
Hi
I created a variable of type String.
How do I display all of its properties?
Thanks
Bye
Nov 15 2022 02:55 PM
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
Nov 16 2022 02:05 AM
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
Nov 16 2022 02:24 AM
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