Powershell Remote Start-Process not Running

Hi there, 

I'm fairly new to powershell but have some behaviour which I cannot explain. 

I start a process on a remote computer with the following command: 

PS C:\Users\Myusername> Invoke-Command {Start-Process calc -passthru} -comp computer010

When the command is run I see the following output: 

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
      0       1      324        124     3     0,03   3564 calc

However when I do a ps calc -comp computer010 I get the following output: 

 Cannot find a process with the name "calc"

What am I doing wrong.. the process seems to start but I can't find it back. Also tried a lot of different ways to start the process, also WMI with the same results.

July 15th, 2015 7:43pm

Invoke command starts a session.  When it completes the session is terminated.

Do this:

$session=New-PsSession computer010
Invoke-Command {Start-Process calc} -Session $session
Get-Process calc -Computer computer010

Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 8:03pm

Thanks dude! Sometimes it's a bit confusing for me when to enter or exit a session... I just build a script to repair an app-v package on our environment, if you want you can have a look at it and maybe you can see some improvements. I need a param within the braces for the computername but you've already shown it in the above command. (the explorer gets killed because the office 2013 package stays in use with the explorer process so it won't repair)

This is the script to repair the package and reboot the machine (can't get explorer back under user session) Restarting explorer won't let the app-v package be 

$readhost = Read-Host "enter computername"
New-PSSession $readhost
Enter-PSSession $readhost
Invoke-Command -ComputerName $readhost -ScriptBlock {taskkill.exe /f /im explorer.exe}
Invoke-Command -ComputerName $readhost -ScriptBlock {Get-AppvClientPackage -name *office* | Repair-AppvClientPackage -Global}
Invoke-command -computername $readhost -scriptblock {Restart-Computer -ComputerName computer010 -force}

The only thing I need to look at the variable computername to let it use the variable. 

July 17th, 2015 2:15am

You are asking a new question.  The code you have posted is not how to use a session.  It won't work.

If you have new questions please start a new topic.

Free Windows Admin Tool Kit Click here and download it now
July 17th, 2015 4:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics