I am trying to execute a powershell script through a batch file, at the moment I am only testing this to get it running so the .ps1 file is simply a hello world script.

This ALMOST works fine except there is a spanner to throw into the works;

I am trying to have the .ps1 stored in a remote location (on a shared NAS to be specific). This works when I have the .ps1 saved locally and point the .bat to the local .ps1.

However now that the .ps1 is in the remote location I am thrown with the following error;

"file (pathname) cannot be loaded. The file (pathname) is not digitally signed. The script will not execute on the system"

Now I am aware of execution policies and mine are as follows;

MachinePolicy  =   RemoteSigned
UserPolicy     =   Undefined
Process        =   Undefined
CurrentUser    =   RemoteSigned
LocalMachine   =   Bypass

I have tried changing CurrentUser to Bypass but I am thrown with the following;

Windows Powershell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope

Screenshot of above error

Any ideas would be greatly appreciated!

Sorry if this has been a lot of information! If any of it is unclear feel free to ask me to clarify! I'm fairly new to all of this!


You can still run the script - you just need to tell PowerShell to bypass the system's executionpolicy like this:

powershell.exe -executionpolicy bypass -file \\server\share\yourscript.ps1

I think the GroupPolicy configured by the company is enforcing the policy to revoke any execution of script from the remote location. Kindly check the Group Policy in the Administrative tools.

  • I think you might be about to make me look very silly.... I tested this on my PC first, which is domain connected and will have access to the NAS. The PC i have been second testing this on is just a local account! Never even crossed my mind! I'll give it a try! Thanks! :) – Csothcott Mar 8 '16 at 15:57
  • Unfortunately no Joy, there is no restrictions on the NAS anyway and I can access it without entering any credentials on the non domain PC :( – Csothcott Mar 8 '16 at 16:36

The other answer might actually be the answer, but in case you (or anyone else) is looking for a workaround, here it is.

In your batchfile, first copy the .ps1 file to a local folder, such as C:\TEMP, and then execute it by using start c:\temp\My_Script.ps1

The command start will make the script work the same way as double clicking it from explorer. You might not actually need to copy it locally if you used a different way to start the file.

  • Unfortunately I can not use this as a work around. We are using an external program to send packages to the PC. This package can send .bat but not .ps1, this is the reason for having to have .bat files launch the .ps1 if this makes sense? – Csothcott Mar 8 '16 at 16:36
  • Why not? Your .bat file accesses the .ps1 file in a way doesn't it? So if your .bat file accesses the .ps1 file, it can also copy it. If you edit your original post and include the contents of your .bat file (feel free to rename some paths) I'll edit my answer and write you how the .bat file should look. – LPChip Mar 8 '16 at 17:11

For the .bat only aspect, a work around would be to make a .bat file that used echo statements to build a local powershell script, then execute the local script

How practical this would be would depend on how complex the script needed to be

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.