Enabling and disabling Powershell script execution
If you’ve ever tried to run Powershell scripts from Windows Powershell you’ve probably seen this error message.
e:\testNativex86.ps1 : File e:\testNativex86.ps1 cannot be loaded because running scripts is disabled on this system.
Whether a Powershell script can run or not is controlled by the Powershell execution policy.
Default execution policy
The default execution policy for Powershell scripts is that Powershell scripts cannot execute.
This may seem like an inconvenient setting, but it is setup like this because it minimises the likelihood that a malicious script, downloaded from the internet, or attached to an email will be executed.
To change the execution policy use the Set-ExecutionPolicy command.
Enabling script execution
To enable script execution in Powershell open an administrator mode Powershell then type this:
Set-ExecutionPolicy RemoteSigned
When prompted answer with: Y
Future attempts to execute scripts will succeed, in this Powershell prompt and in non-administrator mode Powershell prompts.
Disabling script execution
To disable script execution in Powershell open an administrator mode Powershell then type this:
Set-ExecutionPolicy Default
When prompted answer with: Y
Future attempts to execute scripts will fail, in this Powershell prompt and in non-administrator mode Powershell prompts.
32 bit Powershell on 64 bit machines
If you’re using a 64 bit machine you’ll notice that the execution policy that you set on the 64 bit Powershell doesn’t affect the 32 bit Powershell, and vice versa.
To enable or disable script execution for 32 bit Powershell you need to open 32 bit Powershell in administrator mode and set the execution policy there rather than in the 64 bit system default Powershell.
The system Powershells are:
64 bit | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe |
32 bit | C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe |