0

I have created a PowerShell script to get files from a subfolder. This executes when I run from the PowerShell console after manually entering Set-ExecutionPolicy unrestricted, but when I call the same script from a batch file

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe D:\programs\abc\bin\xyz_clean.ps1

it throws an error:

xyz_clean.ps1 cannot be loaded because the execution of scripts is disabled on this system.

9
  • What OS are you running (including 32 vs. 64 bit)? Commented Mar 5, 2013 at 15:20
  • 5
    Have you tried specifying the execution policy in your batch? C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -executionpolicy unrestricted -file D:\programs\abc\bin\xyz_clean.ps1 Aside from that, there may be an issue between your "per user" and "machine" execution policies, you can try playing with the -scope parameter of set-executionpolicy Commented Mar 5, 2013 at 15:22
  • you missing the -file option. Are powershell scripts denied by group policy? Commented Mar 5, 2013 at 15:23
  • Also, are you sure you're running PowerShell v1? The path to the executable is not proof of that, given that it hasn't changed in PS2 and PS3. Try checking the PSVersion attribute of the $psversiontable variable. Commented Mar 5, 2013 at 15:25
  • thnx for the reply my batch file looks like Commented Mar 5, 2013 at 15:26

1 Answer 1

2

You can just call powershell from a command window:

C:\> powershell /?
C:\> powershell -executionpolicy unrestricted -file \\server\file.ps1

then save it to a .bat file:

C:\> echo powershell -executionpolicy unrestricted -file \\server\file.ps1 > file.bat
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.