Nobodys perfect

While PowerShell is by far the best 1.0 release I have worked with in a really long time, it isn’t without its faults.  Today I was trying to figure out if it was possible to programmatically get the type(s) of the object(s) that will be returned from a cmdlet without running that cmdlet.  So far I haven’t been successful, but while exploring I came across a big inconsistency in the current embedded documentation for PowerShell cmdlets.

Take at look at this script:

Get-Command -commandType cmdlet `
    | Add-Member -passThru -name returnType -memberType ScriptProperty -value `
        { (Get-Help $this -full).ReturnValues.ReturnValue.Type.Name } `
    | Add-Member -passThru -name returnTypeDescription -memberType ScriptProperty -value `
        { `
            $description = (Get-Help $this -full).ReturnValues.ReturnValue.Type.Description | out-string; `
            if ($description -ne $null) { $description.Replace(“`r`n”,“”) } `
        } `
    | Format-Table -property name,returnType,returnTypeDescription

This script will get all cmdlets, add two properties to those cmdlets (the return type and the return type description, as extracted from the help documentation), and then output a table with the cmdlet name, the return type and the return type description.  The results, well, they leave a lot to be desired. 🙂

Since the get-help cmdlet only shows the return type and not the return type description in the help documentation it generates, usually the information about the return type is either partially missing or completely missing.

Hopefully this will get cleaned up in a future release of PowerShell.

Oh, and if someone out there knows how to programmatically determine the return type of a cmdlet without calling it and wants to share that knowledge through comments, that would be swell. 🙂

Kirk out.

Technorati Tags: , ,