Make Sure PowerShell Scripts Can Run on Windows
Windows can block PowerShell scripts depending on the current execution policy. If you download or create a .ps1 file and PowerShell refuses to run it, check the execution policy first and choose the least broad setting that works for your test environment.
What It Does
- Shows the current PowerShell execution policy.
- Allows scripts to run for the current user or current PowerShell session.
- Explains the difference between
UnrestrictedandBypass. - Keeps the commands focused on script testing and local admin work.
Check the Current Execution Policy
Open PowerShell and run:
Get-ExecutionPolicy -List
This shows the policy at each scope. A more specific scope, such as Process or CurrentUser, can override a broader machine-level policy.
Allow Scripts for the Current User
Use Unrestricted when you want the current Windows user to be able to run local PowerShell scripts:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
PowerShell may ask you to confirm the change. After this is set, run your script with a path like:
.\script_location\scriptname.ps1
Allow Scripts for This PowerShell Window Only
Use Bypass at the Process scope when you only want the setting to apply to the current PowerShell session:
Set-ExecutionPolicy Bypass -Scope Process
This is useful for one-time testing because the setting goes away when you close that PowerShell window.
Run the Script
After setting the policy, run the script from PowerShell:
.\script_location\scriptname.ps1
For example:
Set-Location C:\Scripts .\genpptx.ps1
When you are done testing, you can set your current-user policy back to a more restrictive default:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser