Invoke-Command remote computer

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Don Jones Don Jones 2 months, 1 week ago.

  • Author
  • #70400
    Profile photo of Creed Cordonier
    Creed Cordonier


    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
    } 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"} 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!

  • #70478
    Profile photo of Don Jones
    Don Jones

    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?

    • #70529
      Profile photo of Creed Cordonier
      Creed Cordonier

      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} 
      {"$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.

  • #70624
    Profile photo of Max Kozlov
    Max Kozlov

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

  • #70649
    Profile photo of Don Jones
    Don Jones

    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.

You must be logged in to reply to this topic.