Question

I am not able to execute the Powershell file script from C# with Invoke-Command on a remote machine but at the same time I am able to execute the same script file using Invoke-Command on a remote machine through the PowerShell Command window with out any issue.

My remote machine as well as local machine has been enabled for Remoting by executing the call Enable-PsRemoting on both the machines. I also set the ExecutionPolicy on both the machines as Unrestricted.

While executing the script I get the following error/execption:

File G:\x.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

I cannot understand what is the issue here.

No correct solution

OTHER TIPS

Is this machine running a 64-bit OS? If it is, there will be both 32 and 64 bit PowerShell environments, and each has it's own execution policy. Depending on how you're invoking the script you may not be running in the same environment and execution policy as what you're using interactively in the command window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top