Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

get-process strange behaviour

$
0
0

Today I encountered some weird behaviour by the get-process command. I was working on a tool to get a list of open programs on a remote computer when I encountered some strange behaviour/inconsistencies, even within the host itself (without remotely connecting and querying).

Once I use the get-process -name command to get the session ID for each instance, it works fine on the local machine, if I run it like this:

(get-process -Name Explorer).SessionId

But one I run this ‘remote’ by specifying a computername (or even localhost on host itself), it returns session 0 for all instances

(get-process -Name Explorer -ComputerName"LOCALHOST").SessionId

Once I use Invoke-Command to ‘remotely’ run the first command, It again works like expected.

Invoke-Command {(get-Process -Name"Explorer").SessionId} -ComputerName 'LOCALHOST'

These are the commands and their output:

Get-Process strange behaviour

Does anyone know why it would lose the session information once I specify the computer name?

It appears that if I would like to check for CPU usage, the first and the third command again work fine, but the 2nd command doesn’t return anything at all!

Is this a powershell bug, a get-process (in combination with -ComputerName) bug, or is this by design and default behaviour?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>