Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
What OS are you running (including 32 vs. 64 bit)? –  alroc Mar 5 '13 at 15:20
4  
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 –  Poorkenny Mar 5 '13 at 15:22
    
you missing the -file option. Are powershell scripts denied by group policy? –  James Woolfenden Mar 5 '13 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. –  Poorkenny Mar 5 '13 at 15:25
    
thnx for the reply my batch file looks like –  Abhijeet Bhujbbal Mar 5 '13 at 15:26

1 Answer 1

You can just user powershell in a batch file

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

Save it to a bat file

C:\> echo powershell -executionpolicy unrestricted -file \\server\file.ps1 > file.bat
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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