如何在 PowerShell 中从 Invoke-Command 输出中排除 PSComputerName 属性?

powershellmicrosoft technologiessoftware & coding

使用 Invoke-Command 时,输出表中会多出一个 PSComputerName 字段。您可以使用 -HideComputerName 参数将其移除。例如,以下命令的输出包含 PSComputerName 属性。

示例

Invoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Service Winrm} | ft -AutoSize

输出

Status  Name  DisplayName                               PSComputerName
------  ----  -----------                               --------------
Running Winrm Windows Remote Management (WS-Management) LabMachine2k12

要隐藏 PSComputerName 属性,

示例

Invoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Service Winrm} -HideComputerName

输出

Status  Name  DisplayName  
------  ----  -----------  
Running Winrm Windows Remote Management (WS-Management)

相关文章