Is there a way to get the return type for a PowerShell cmdlet from the Get-Help command? I prefer to get this information without actually invoking the command and use GetType() on it. Seems like the object return type should be in the documentation somewhere?
Example: I type Get-Help Get-Content. Where in the documentation does it tell me it returns a String Object? or String[] object?
Is there some flag I need to provide to Get-Help to get this information?
Get-Command can also be helpful in this scenario:
PS C:\> Get-Command Get-Content |Select OutputType
OutputType
----------
{System.Byte, System.String}
If you run Get-Help -Name Get-Content -Full, you'll see all the help members. For your question, there is an OUTPUTS field:
OUTPUTS
System.Object, System.String
Get-Content returns objects that represent the content that it gets.
The object type depends on the content type. If you use the Stream
parameter, the cmdlet returns the alternate data stream contents as
a string.
An array isn't really a type all on its own, but you can force anything to return an array to you by wrapping it in an array literal:
File.txt
This is one line of text
Command:
@(Get-Content -Path File.txt)
Now you can access the .Count and other array type members and when you use -match (for example), it will return the full string if it is successful instead of $True/$False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With