【问题标题】:Does Get-Help tell you the type returned by a cmdlet?Get-Help 是否告诉您 cmdlet 返回的类型?
【发布时间】:2017-12-12 23:14:36
【问题描述】:

有没有办法从Get-Help 命令获取 PowerShell cmdlet 的返回类型?我更喜欢在不实际调用命令的情况下获取此信息并在其上使用GetType()。似乎对象返回类型应该在文档中的某个地方?

示例:我输入Get-Help Get-Content。它在文档中的什么地方告诉我它返回一个String 对象?或String[] 对象?

我需要向Get-Help 提供一些标志以获取此信息吗?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    Get-Command 在这种情况下也有帮助:

    PS C:\> Get-Command Get-Content |Select OutputType
    
    OutputType
    ----------
    {System.Byte, System.String}
    

    【讨论】:

      【解决方案2】:

      如果您运行Get-Help -Name Get-Content -Full,您将看到所有帮助成员。对于您的问题,有一个OUTPUTS 字段:

      OUTPUTS  
          System.Object, System.String  
              Get-Content returns objects that represent the content that it gets.
              The object type depends on the content type. If you use the Stream
              parameter, the cmdlet returns the alternate data stream contents as
              a string.
      

      数组本身并不是一个真正的类型,但是您可以通过将数组包装在数组文字中来强制任何东西返回数组:

      文件.txt

      This is one line of text
      

      命令:

      @(Get-Content -Path File.txt)
      

      现在您可以访问.Count 和其他数组类型成员,当您使用-match(例如)时,如果成功,它将返回完整字符串而不是$True/$False

      【讨论】:

      • 我刚刚发现你可以输入:“get-help -showwindow get-content”,它在弹出第二个窗口时隐式添加了-full..
      • @BillMoore 是的!您也可以使用-Online 开关来调出您的默认浏览器,该浏览器指向具有相同信息的帮助源,但在浏览器中,因此您可以更轻松地搜索它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多