Weird get-process behaviour

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!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: