Step 1: Open PowerShell as Administrator
- Click the Start button, type
powershell
. - Right-click on Windows PowerShell and select Run as Administrator. This is necessary because changing the execution policy requires administrator privileges.
Step 2: Check the Current Execution Policy
Before making any changes, it’s a good idea to check the current execution policy. Run the following command:
powershellCopy code Get-ExecutionPolicy
This will return the current execution policy. Common policies are:
- Restricted: No scripts can run.
- RemoteSigned: Scripts downloaded from the internet must be signed by a trusted publisher.
- Unrestricted: Scripts can run without any restrictions.
Step 3: Change the Execution Policy
To enable script execution, you need to change the execution policy. You can set it to RemoteSigned, which allows locally created scripts to run but requires that downloaded scripts are signed by a trusted publisher. This is the most common setting for running scripts safely.
Run the following command:
powershellCopy code Set-ExecutionPolicy RemoteSigned
After running the command, you’ll be prompted to confirm the change. Type Y and press Enter to apply the new policy.
Step 4: Verify the Execution Policy Change
After changing the execution policy, it’s a good idea to verify the change by running:
powershellCopy code Get-ExecutionPolicy
This should return RemoteSigned
(or whatever policy you set).
Step 5: Run Your Script
Now, you should be able to run PowerShell scripts without encountering the “execution of scripts is disabled” error.
Optional: Allow All Scripts (Less Secure)
If you want to allow all scripts to run, you can set the execution policy to Unrestricted. Keep in mind that this is less secure, as it will allow any script to run, even those that haven’t been signed.
powershellCopy code Set-ExecutionPolicy Unrestricted
Revert to the Default Execution Policy
If you want to revert to the default Restricted policy later, run:
powershellCopy code Set-ExecutionPolicy Restricted
Conclusion
By adjusting the execution policy, you can enable the running of PowerShell scripts on your Windows 10 system. The RemoteSigned policy is a good balance between security and functionality, allowing you to run your own scripts while maintaining some protection against malicious code from the internet.
Make sure to always be cautious when running scripts, especially if they’re downloaded from the web or shared by someone you don’t trust.