If you encounter an error when running a PowerShell script, you need to change the execution policy. Here's how to do it.
Channel | Publish Date | Thumbnail & View Count | Actions |
---|---|---|---|
Failed to fetch data | 0 Views |
Change PowerShell execution policy to run scripts on Windows
By default, when you try to run a script in PowerShell on Windows 11 (or 10), it fails with the error message "Cannot load because script execution is disabled on this system." This is because PowerShell has a security feature called "Execution Policy" that controls how configuration files are loaded and scripts are executed to prevent malicious code from executing on the system.
If you need to run a script on Windows 11 (or 10), you can change the execution policy for the local computer, the current user, or the session.
When you set a PowerShell execution policy for the local computer and the current user, the information is stored in the registry. If you configure the policy for a specific session, the policy is held in memory and is lost when you close the session.