PowerShell: CPU usage remote pc

Use the powershell command below to get the list of processes on a remote Windows computer, sorted by CPU usage.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$remoteComputerName = "rdwevw25"
$session = New-PSSession -ComputerName $remoteComputerName
$scriptBlock = {
Get-Process | Sort-Object -Property cpu -Descending
}
$result = Invoke-Command -Session $session -ScriptBlock $scriptBlock
Remove-PSSession -Session $session
$result
$remoteComputerName = "rdwevw25" $session = New-PSSession -ComputerName $remoteComputerName $scriptBlock = { Get-Process | Sort-Object -Property cpu -Descending } $result = Invoke-Command -Session $session -ScriptBlock $scriptBlock Remove-PSSession -Session $session $result
$remoteComputerName = "rdwevw25"
$session = New-PSSession -ComputerName $remoteComputerName
$scriptBlock = {
   Get-Process | Sort-Object -Property cpu -Descending

}

$result = Invoke-Command -Session $session -ScriptBlock $scriptBlock
Remove-PSSession -Session $session

$result
Share your love