Reputation: 3
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.
Upvotes: 0
Views: 5761
Reputation: 2166
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
Upvotes: 2