Zephyrus 1898
Zephyrus 1898

Reputation: 5

Get-Help format is different when calling it in a script

I am wondering why my PowerShell get-help outputs like the following image when using a script I've written. The script's purpose is to display get-help information when selecting a function from an array.

#Run this file in the same directory as the Functions file.

#this function validates user input
function getInput
{
    do
    {
            $input = Read-Host "`n>Enter function # to see its description"

    }until(([int]$input -gt 0) -and ([int]$input -le $flist.count))

    $input
}

#include the script we want
. "$PSScriptRoot\functions.ps1"

#This operates on a loop. After viewing your help info, press key and you will be prompted to choose another function.
$quit = 0
while(!$quit){
    #get all functions
    $f = @(get-content functions.ps1 | where-object { $_.StartsWith("function", "CurrentCultureIgnoreCase") -and (-not $_.Contains("#")); $c++} | sort-object)

     "There are " + $f.count + " functions!"

    #split on ' ', get second word (function name), add to array
    $flist = @{}
    $i = 0
    foreach($line in $f){
        $temp = $line.split(' ')
        $temp[1]
        $i++
        $flist.add($i, $temp[1])
    }

    #print, order ascending
    $flist.GetEnumerator() | sort -Property name

    #accept user input
    $input = getInput

    #get-help about the chosen function
    "Get-Help " + $flist[[int]$input]
    Get-Help Add-ADGrouptoLocalGroup | format-list
    #Get-Help $flist[[int]$input] -full
    Get-Command $flist[[int]$input] -syntax
    Pause
}

The target script $PSScriptRoot\Functions.ps1 has a bunch of functions in it. What my script is doing is this:

Each function has the <#.SYNOPSIS .DESCRIPTION ... etc #> comment block in it (You can see the function's details--from the function's comment help-block--in the provided image). If I run get-help on the function within the target script, it appears to be formatted normally--but that's not the case when using script I've written.

What is really bothering me is the @{Text = 'stuff'} formatting, etc. Thanks ahead of time!

My Script's Get-Help output

Upvotes: 0

Views: 59

Answers (1)

Χpẘ
Χpẘ

Reputation: 3451

You're piping the output of get-help through format-list. This "overrides" the default formatting PS does on the PSCustomObject (in PS 3.0 at least) that get-help creates. You should be able to just invoke get-help by itself and not pipe it. If that doesn't work, then pipe it through out-default.

See help about_format for more details.

Upvotes: 1

Related Questions