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.
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:22PSVersion
attribute of the$psversiontable
variable. – Poorkenny Mar 5 '13 at 15:25