To execute a PowerShell script, open PowerShell, type .\script.ps1, and press Enter — first checking the execution policy with Get-ExecutionPolicy.
Running scripts is where PowerShell earns its keep, but the first attempt often fails with a red error about execution policy. Knowing how to execute a PowerShell script means understanding two things: the command itself and the safety gate that controls whether it runs. Here is the exact sequence that works every time.
What Does the Execution Policy Do?
PowerShell’s execution policy is a safety feature that decides whether scripts can run on your machine. It is not a hard security boundary — it is more like a warning system that helps prevent accidentally running malicious code.
To see the current policy for your session, open PowerShell and run:
Get-ExecutionPolicy
The output shows one of several values that determine what scripts are allowed. The default on most Windows systems is Restricted, which blocks all scripts. To check a specific scope, add the -Scope parameter:
Get-ExecutionPolicy -Scope CurrentUser
The most restrictive policy in the chain wins, so checking just one scope can be misleading.
Change the Execution Policy If Needed
If your policy blocks scripts, use Set-ExecutionPolicy to change it. The change takes effect immediately — no restart required.
The two most common settings are RemoteSigned and AllSigned:
- RemoteSigned — scripts downloaded from the internet must be signed by a trusted publisher; local scripts run without a signature.
- AllSigned — all scripts must be signed by a trusted publisher, whether local or remote.
Run this command as Administrator to set the policy:
Set-ExecutionPolicy RemoteSigned
Type Y and press Enter when prompted. Microsoft recommends RemoteSigned as a balanced starting point for most users — it allows your own scripts while blocking unsigned remote downloads.
Running PowerShell Scripts: The Step Order That Works
Once the execution policy permits scripts, running a .ps1 file is one command away. The format depends on where the script is located.
For a script in the current directory:
.\scriptname.ps1
The .\ prefix tells PowerShell to look in the current folder. Omitting it is the single most common mistake — PowerShell ignores bare script names as a safety measure.
For a script at a different location:
C:\Scripts\MyScript.ps1
Use the full absolute path to run a script from any directory without changing your current location.
For a script with parameters:
.\script.ps1 -ComputerName Server01 -Path "C:\Logs"
Type the parameters right after the script filename, then press Enter.
From File Explorer: right-click the .ps1 file and select Run with PowerShell. The console window may close automatically after the script finishes, so you might miss the output. Open PowerShell manually if you need to see results.
Execution Policy Values: What Each One Means
| Policy | What It Does |
|---|---|
| Restricted | Blocks all script execution — the default on most Windows systems. |
| RemoteSigned | Signatures required for internet-downloaded scripts; local scripts run freely. |
| AllSigned | Every script must carry a trusted digital signature. |
| Unrestricted | All scripts run, but Windows prompts before running unsigned internet scripts. |
| Bypass | Scripts run without any restriction — useful for one-off sessions. |
| Undefined | Removes the policy assignment for the current scope; falls back to the next scope. |
| Default | Sets the policy to the platform’s default (Restricted on desktop, RemoteSigned on Server). |
Use the least permissive policy that still lets you work. For personal scripts, RemoteSigned hits that balance cleanly.
Can You Run Scripts on Remote Computers?
Yes — use the Invoke-Command cmdlet with the -FilePath parameter. The script file must exist on the local computer or in a directory the local machine can access; it does not need to be copied to the remote machine first.
Invoke-Command -ComputerName Server02 -FilePath "C:\Scripts\Deploy.ps1"
PowerShell transfers the script to the remote computer and executes it there. Add more computer names or use a variable to target multiple machines at once.
Common Mistakes That Trip Up Beginners
Even experienced users hit these same blockers. Watch for them before you run:
- Forgetting the .\ prefix. Typing
script.ps1instead of.\script.ps1in the current directory returns a security error. The dot-slash form is required for files in the working folder. - Not checking the execution policy first. A blocked script produces a red error that looks serious but is fixed with one command.
- Assuming a policy change needs a restart.
Set-ExecutionPolicyapplies immediately. Close PowerShell only if you want a fresh session. - Using Invoke-Command with an inaccessible script. The script must live where the local computer can read it. Network paths work only with proper access.
- Running an unsigned script from the internet without reviewing it. Execution policy is not a hard security boundary — always inspect code from untrusted sources before running it.
Quick Reference for Common Execution Tasks
| Task | Command |
|---|---|
| Check current execution policy | Get-ExecutionPolicy |
| Check policy for current user | Get-ExecutionPolicy -Scope CurrentUser |
| Set policy to RemoteSigned | Set-ExecutionPolicy RemoteSigned |
| Set policy for one session only | pwsh.exe -ExecutionPolicy Bypass |
| Run script in current directory | .\script.ps1 |
| Run script with full path | C:\Path\script.ps1 |
| Run script remotely | Invoke-Command -ComputerName PC01 -FilePath .\script.ps1 |
Finish With the Right Execution Order
- Save your script with a .ps1 extension.
- Open PowerShell — Run as Administrator if you need to change the execution policy.
- Run
Get-ExecutionPolicyto check the current policy. - If the policy is Restricted, run
Set-ExecutionPolicy RemoteSignedas Administrator. - Navigate to the script’s folder or type its full path.
- Type
.\scriptname.ps1and press Enter. - Add any parameters after the filename, then review the output for errors.
References & Sources
- Microsoft. “About Scripts — PowerShell.” Official documentation for creating and running PowerShell scripts.
