PowerShell Help files do not display correctly
Tested in PowerShell 4.0, 5.0 on Windows 10 and Windows Server 2012:
clear
help *-wmiobject*
or
cls
man *-job*
The help file does not display the results correctly after clearing the screen. Re-run the command and it works as expected.
Get-Help is unaffected.
What is the reason for this?
thank
source to share
Funny mistake. The reason (presumably) is that the search progress bar "Search for Help" is updated after Powershell displays the call results help()
, effectively clearing 8 lines from line # 2 to # 9 from the top. The workaround is the result in a temporary variable.
$temp=help *-wmiobject; $temp
This ensures that the function exits before displaying the material, so the progress bar is removed from the window.
UPDATE: There is no error if you did not supply asterisks in the argument help
. Therefore, an error can occur because the mapping is performed in the "Process" part help()
, and the code that clears the progress bar is in the "End" part of the function.
source to share
I can reproduce this on a 64-bit Windows 8.1 machine on both PowerShell consoles (32/64-bit)
The short version is a more.com
DOS command that is used by man
and help
but not Get-Help
.
Get-Help, help, man: what's the difference?
Better explained by Don Jones * and this Script Fanatic post :
more
you run (Get-ChildItem function:\help).definition
, as described in a blog post, you'll see it at the bottom:
Get-Help @PSBoundParameters | more
help
basically binds parameters to Get-Help
Cmdlet and pipe to more
. So, as you posted, you will have the same problem if you use:
clear
Get-Help *et-WmiObjec* | more # doesn't work
I suppose it Get-Help
uses Out-Host
the default for outputting information (quote needed). Usage Write-Output
also works.
clear
help *-wmiobject* | Out-Host # works
clear
man *-wmiobject* | Out-Host # works
Finally, this appears to be an issue where multiple results are returned man
/ help
.
clear
man get-WmiObject # works
I recommend checking the documentation and helping out with this. From the results, (Get-ChildItem function:\more).definition
I suspect it has to do with handling arrays / objects line by line, but that depends on my knowledge.
param([string[]]$paths)
$OutputEncoding = [System.Console]::OutputEncoding
if($paths)
{
foreach ($file in $paths)
{
Get-Content $file | more.com
}
}
else
{
$input | more.com
}
* PowerShell Lunch Month, 2nd ed., P. 23
source to share