How to exclude the RunSpaceID property from the Invoke-Command output in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

When we write Invoke-Command in PowerShell, sometimes we get the RunSpaceID property in PowerShell. This is because we use Select-Object (alias: Select) command inside the scriptblock. For example,

Example

Invoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell | Select Name, CPU, WorkingSet}

Output

Name           : powershell
CPU            : 9.1572587
WorkingSet     : 127700992
PSComputerName : LabMachine2k12
RunspaceId     : c690f205-06d4-4cc4-be29-5302725eadf1

To avoid getting the RunSpaceID property in the output, use the Select command output the scriptblock. For example,

Example

Invoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell} | Select Name, CPU, WorkingSet

Output

Name       CPU        WorkingSet
----       ---        ----------
powershell 9.1572587  127700992
raja
Published on 08-Feb-2021 07:50:11
Advertisements