3

I'm very new to Windows scripting and am having an issue with trying to execute a Powershell script located on a remote node.

It's a super simple HelloWorld script.

I'm setting up my session and issuing the remote invocation command like this ::

$session = New-PSSession -ComputerName DH2VCAUSPTCTX01.XXX.XXX.com -Credential XXX\XXX

Invoke-Command -Session $session -FilePath C:\Users\Public\EOD_CWx_Scripts\hello_world_PS.ps1

I keep getting this error ::

Invoke-Command : Cannot find path 'C:\Users\Public\EOD_CWx_Scripts\hello_world_PS.ps1' because it does not exist. At line:1 char:1 + Invoke-Command -Session $session -FilePath C:\Users\Public\EOD_CWx_Sc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Public...lo_world_PS.ps1:String) [Invoke-Command], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand


This is a screen shot of the Remote node showing that the file does indeed exist :: enter image description here

This is a screen shot of me attempting to invoke the Powershell script on the remote node :: enter image description here


Like I said, I'm really new to Windows scripting.

Is there something that I'm missing when it comes to remotely invoking Powershell scripts?

For reference, I've been using this resource to try and figure out how to do this :: https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/invoke-command

Chiefwarpaint
  • 643
  • 2
  • 12
  • 25
  • 6
    The very first example in [the documentation](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/invoke-command) shows this exact scenario as well as your thinko: "The command uses the `FilePath` parameter to specify a script that is located on the *local computer*. The script runs on the remote computer and the results are returned to the local computer." (emphasis mine). Usually having the script locally is convenient. If it must be remote, pass a scriptblock with `{ & "script.ps1" }` instead. – Jeroen Mostert Aug 02 '17 at 15:39
  • 1
    Geeeeeze, I knew it had to be something dumb I was doing. Thanks a ton @JeroenMostert My Powershell script just executes a .bat file that says, "Hello World" and I can see the cmd process getting spun up now after switching my command to use the scriptblock arg. – Chiefwarpaint Aug 02 '17 at 15:43

0 Answers0