Search code examples
powershellpowershell-4.0

Raw data in Custom Comments with functions in power-shell when piping to a Format-Table


I'm trying create a cheat sheet for a power-shell module that I'm writing. I am using the custom help message that you can add into a function in a powershell module. Then Calling the Get-Help on each method then selecting some specific output and formatting out to a table. I'm getting stuck trying to get at the raw data that you can bind with the Get-Help functionality.

sample power-shell module

# example_psmod_psm1

#this is a test
function commitWithMessage() {
<#
.SYNOPSIS
git commit --verbose --message
.DESCRIPTION 
gitcm
.NOTES
Commits to local git repo with verbose and message flag 
#>  
   git commit --verbose --message $args[0]
}

The get help call works fine and will display the correct information on a single page when I make the following call.

Get-Help commitWithMessage

get-help

but I when i try to select specific fields and then output it in table form with the following command.

Get-Help commitWithMessage | Format-Table "DESCRIPTION", "SYNOPSIS","NOTES"

I get the following.

enter image description here

I'm trying to figure out what the description is wrapped in. and how to get at the text data. And it appears that the notes are not being pulled from the file


Solution

  • The format cmdlets wrap the output in more complex objects (Microsoft.PowerShell.Commands.Internal.Format...) You can inspect them in your case by using

    Get-Help commitWithMessage | Format-Table "DESCRIPTION", "SYNOPSIS","NOTES" | get-member
    

    I guess you're searching for:

    get-help commitWithMessage | select-object -ExpandProperty Description