powershell - Get-Help format is different when calling it in a script -
i wondering why powershell get-help
outputs following image when using script i've written. script's purpose display get-help
information when selecting function array.
#run file in same directory functions file. #this function validates user input function getinput { { $input = read-host "`n>enter function # see description" }until(([int]$input -gt 0) -and ([int]$input -le $flist.count)) $input } #include script want . "$psscriptroot\functions.ps1" #this operates on loop. after viewing info, press key , prompted choose function. $quit = 0 while(!$quit){ #get functions $f = @(get-content functions.ps1 | where-object { $_.startswith("function", "currentcultureignorecase") -and (-not $_.contains("#")); $c++} | sort-object) "there " + $f.count + " functions!" #split on ' ', second word (function name), add 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 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 bunch of functions in it. script doing this:
- list functions found within target file.
- put name in indexed array
- prompt user function get-help on, @ given index
- print get-help , get-syntax on selected function
each function has <#.synopsis .description ... etc #> comment block in (you can see function's details--from function's comment help-block--in provided image). if run get-help on function within target script, appears formatted normally--but that's not case when using script i've written.
what bothering me @{text = 'stuff'} formatting, etc. ahead of time!
you're piping output of get-help
through format-list. "overrides" default formatting ps on pscustomobject
(in ps 3.0 @ least) get-help
creates. should able invoke get-help , not pipe it. if doesn't work, pipe through out-default
.
see help about_format
more details.
Comments
Post a Comment