A coworker in Denver sent me a message one Monday: she’d saved her first cleanup script as a .ps1 file, double-clicked it, and Notepad opened. To run a PowerShell script, open PowerShell in the script’s folder and type its name with .\ in front:
.\Get-SalesReport.ps1
In this tutorial, I’ll show you how to run a PowerShell script from the console, Command Prompt, the Run dialog and File Explorer. I’ll also fix execution policy errors safely, pass parameters and point out where PowerShell 7 and 5.1 differ.
Quick answer: the method depends on where you start from:
| Where you are | What to type |
|---|---|
| PowerShell console, same folder | .\Get-SalesReport.ps1 |
| PowerShell console, any folder | & "C:\psfaqs\Sales Reports\Get-SalesReport.ps1" |
| Command Prompt or Win+R (5.1) | powershell -ExecutionPolicy Bypass -File "C:\path\script.ps1" |
| Command Prompt or Win+R (7) | pwsh -File "C:\path\script.ps1" |
| File Explorer | Right-click the file and choose Run with PowerShell |
Create a sample .ps1 script to run
Every method below runs the same small script, so you can follow along. Open Notepad or VS Code, paste this code, and save it as Get-SalesReport.ps1 in a folder such as C:\psfaqs. Pick All files in Notepad’s Save dialog so it doesn’t add .txt:
param(
[string]$City = 'Austin',
[string[]]$State = 'TX',
[switch]$Detailed
)
$sales = @{ Austin = 18450.75; Denver = 12980.40; Seattle = 22315.10 }
"Sales report for $City, October 2026: `$" + $sales[$City].ToString('N2')
"States ($($State.Count)): $($State -join ', ')"
if ($Detailed) { "Script folder: $PSScriptRoot" }
Output:
Sales report for Austin, October 2026: $18,450.75
States (1): TX
The param block defines three optional parameters: a city, one or more states and a -Detailed switch. With no arguments, it reports Austin and TX. For more starter ideas, see these practical PowerShell script examples.
A .ps1 file is plain text, so double-clicking it only opens an editor. That’s a deliberate security feature, so a script can’t run by accident from a single click.
How do you run a PowerShell script from the PowerShell console?
This is the method I use every day. It takes three steps, and it shows you the output and any errors in the same window.
Step 1: Open PowerShell. Click Start, type PowerShell, and open Windows PowerShell or PowerShell 7. Windows Terminal works too, since it opens PowerShell tabs.
Step 2: Go to the script’s folder. Use Set-Location (alias cd). Here’s how to change the directory in PowerShell if the path is long.
Step 3: Type .\ and the file name. The .\ means “this folder”. You can also type the full path from anywhere:
Set-Location -Path C:\psfaqs
.\Get-SalesReport.ps1 -City Denver
C:\psfaqs\Get-SalesReport.ps1 -City Seattle
Output:
Sales report for Denver, October 2026: $12,980.40
States (1): TX
Sales report for Seattle, October 2026: $22,315.10
States (1): TX