Author Posts

May 9, 2017 at 3:52 pm

Hello,

I have read all kinds of documentation and examples, but I simply cannot start this .exe using Invoke-Command. I look for it in the processes list and it never starts on the remote system, but I do not get any error in my local console. Here it is...

Invoke-Command -ComputerName remotecomp -ScriptBlock {

$ccmCleanLocal = "C:\hold-1\ccmclean.exe"

if ([System.IO.File]::Exists($ccmCleanLocal)) {

Start-Process -FilePath $ccmCleanLocal

$wait = Get-Process ccmclean.exe

$wait.WaitForExit()

} Else {"ccmclean is not in hold-1"}

}

No errors on my end. The process never starts on the remote computer. PS remoting works, as if I change the if statement to:

if ([System.IO.File]::Exists($ccmCleanLocal)) {"yep"}

...my console will return yep. I can also do other tasks remotely. Also if I remove ccmclean.exe from \hold-1, my console tells me it is not there.

I have tried adding -credential, still does not work.

Why wouldn't this work?!

Thank you!

May 10, 2017 at 1:51 pm

You might find that Test-Path offers a "cleaner looking" way of testing for the presence of the executable.

Are you able to connect to the remote computer using Enter-PSSession, and then simply run your Start-Process command interactively, to see what happens?

May 11, 2017 at 12:33 pm

Hi Don,

The plan is to run this as part of a script on several machines at once. I am not sure Enter-PSSession would work in that scenario?

I got this to work (mostly) by using PSExec...

ForEach ($pc in $list) {

$cmd = "C:\hold-1\ccmclean.exe"

$args = "/Q"

if ((Test-Connection -ComputerName $pc -Quiet) -And (Test-Path -Path "\\$pc\c$\Hold-1\ccmclean.exe")) { & "C:\PSTools\psexec.exe" \\$pc $cmd} 

Else 

{"$pc is not online, or ccmclean is not in \Hold-1"}

} 

What I cannot seem to do properly is add args to the ccmclean.exe command. I need to run it with /Q.

May 15, 2017 at 6:53 am

Start-Process [-FilePath] [[-ArgumentList] ]

May 15, 2017 at 12:46 pm

My suggestion with using Enter-PSSession was as a troubleshooting step. If you can get the command to run that way, then you'll know you have the correct syntax and permissions and everything, and then you can copy and paste the working command into a script.