Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Problem with running a remote script within a script.

$
0
0

I've got a script that's on one of my servers.

I wanted to make a new script (which i can distribute to others at the IT-dept) that would enter a pssession and invoke-command the script.

I've been troubleshooting this issue for a while now, trying different ways and solutions, but it seems that whenever i enter a new pssession it doesn't load the remote filesystem but instead stays on local.

Running this:

$Session=New-PSSession-ComputerName server01 -Credential administrator
Invoke-Command-Session$Session-FilePath C:\scripts\script.ps1

 

ends with error:

Invoke-Command : Cannot find path 'C:\scripts\script.ps1' because it does not exist.
At line:2 char:1
+ Invoke-Command -Session $Session -FilePath C:\scripts\script.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\scripts\script.ps1:String) [Invoke-Command], ItemN
   otFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand

 

So tried just making a

etsn server01 -credential administrator

set-location C:\scripts

 

And that too fails with error that the path doesn't exist.

Any clues why this is happening?


Viewing all articles
Browse latest Browse all 8583

Trending Articles