我正在编写一个powershell脚本,其中需要获取文件的“获取帮助”信息并在模式窗口中向用户显示。当我从控制台运行命令时,它显示得非常好:
globit()
但是将其直接管道输送到外部窗口将如下所示:
NAME
Format-Table
SYNOPSIS
Formats the output as a table.
SYNTAX
Format-Table [[-Property] <Object[]>] [-AutoSize] [-DisplayError] [-Expand {CoreOnly | EnumOnly | Both}] [-Force] [-GroupBy <Object>] [-HideTableHeaders] [-InputObject <PSObject>] [-ShowError] [-View <String>] [-Wrap] [<CommonParameters>]
DESCRIPTION
The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column, but you can use the Property
parameter to select the properties that you want to see.
You can also use a hash table to add calculated properties to an object before displaying it and to specify the column headings in the table. To add a calculated property, use the Property or GroupBy parameter.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821775
Format-Custom
Format-Hex
Format-List
Format-Wide
REMARKS
To see the examples, type: "get-help Format-Table -examples".
For more information, type: "get-help Format-Table -detailed".
For technical information, type: "get-help Format-Table -full".
For online help, type: "get-help Format-Table -online"
我意识到这是因为它实际上不是一个字符串,但是我在弄清楚如何解析返回的MamlCommandHelpInfo以便很好地显示在控制台之外时遇到了麻烦。对于Get-Info返回对象的某些元素,我可以执行类似的操作以挑选出各个部分(尽管即使此输出需要更多格式):
@{examples=@{example=System.Management.Automation.PSObject[]}; inputTypes=@{inputType=@{type=@{name=System.Management.Automation.PSObject}; description=System.Management.Automation.PSObject[]}}; alertSet=@{alert=System.Management.Automation.PSObject[]}; syntax=@{syntaxItem=@{name=Format-Table; parameter=System.Management.Automation.PSObject[]}}; parameters=@{parameter=System.Management.Automation.PSObject[]}; details=@{description=System.Management.Automation.PSObject[]; verb=Format; noun=Table; name=Format-Table}; description=System.Management.Automation.PSObject[]; relatedLinks=@{navigationLink=System.Management.Automation.PSObject[]}; returnValues=@{returnValue=@{type=@{name=Microsoft.PowerShell.Commands.Internal.Format}; description=System.Management.Automation.PSObject[]}}; xmlns:maml=http://schemas.microsoft.com/maml/2004/10; xmlns:command=http://schemas.microsoft.com/maml/dev/command/2004/10; xmlns:dev=http://schemas.microsoft.com/maml/dev/2004/10; xmlns:MSHelp=http://msdn.microsoft.com/mshelp; Name=Format-Table; Category=Cmdlet; Synopsis=Formats the output as a table.; Component=; Role=; Functionality=; PSSnapIn=; ModuleName=Microsoft.PowerShell.Utility}
但是对于诸如参数部分之类的东西,我一直点击PSObject [],并循环遍历,我无法从单个对象中获取任何信息(我假定这些对象包含参数数组)。
必须有一个更好的方法来执行此操作...有什么想法/技巧吗?谢谢!