如何从PowerShell的Invoke-Command输出中排除RunSpaceID属性?

当我们在PowerShell中编写Invoke-Command时,有时会在PowerShell中获得RunSpaceID属性。这是因为我们在脚本块中使用了Select-Object(别名:Select)命令。例如,

示例

Invoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell | Select Name, CPU, WorkingSet}
输出结果
Name           : powershell
CPU            : 9.1572587
WorkingSet     : 127700992
PSComputerName : LabMachine2k12
RunspaceId     : c690f205-06d4-4cc4-be29-5302725eadf1

为了避免在输出中获取RunSpaceID属性,请使用Select命令输出脚本块。例如,

示例

Invoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell} | Select Name, CPU, WorkingSet
输出结果
Name       CPU        WorkingSet
----       ---        ----------
powershell 9.1572587  127700992