Reputation: 1467
Quite simply:
> powershell.exe -command "& '\\RemoteServer\c$\My Script.ps1'"
does not work at all. My Script.ps1
opens in Notepad, nothing more. Meanwhile,
> powershell
PS > &"\\RemoteServer\c$\My Script.ps1"
works just fine (the script executes).
I did have to use the caspol
tool, since my script relies on a binary module, but I don't see how that could be the issue.
Any thoughts as to the cause of this issue?
Thanks!
Upvotes: 1
Views: 1257
Reputation: 72680
Perhaps your problem is the white space in your script name, here is a solution if you want to call from cmd.exe :
C:\>powershell.exe -nologo -command "&{$a=\"\\RemoteServer\c$\My Script.ps1\";& $a}"
\"
prevent cmd.exe from interpreting "
character
If you want to execute it into a powershell.exe command prompt :
PS C:\>powershell.exe -nologo -command "&{`$a='\\WM2008R2ENT\c$\temp\Aff le loup.ps1';& `$a}"
$ prevent powershell.exe from interpreting
$` character
Hope it helps
JP
Upvotes: 0
Reputation: 3429
Try...
powershell.exe -nologo -command "&{\\RemoteServer\c$\My Script.ps1}"
Upvotes: 1
Reputation: 37398
Try...
powershell.exe . '\\RemoteServer\c$\My Script.ps1'
Upvotes: 1