How to Run a PowerShell Script from CMD (With Parameters)

To run a PowerShell script from cmd, type powershell with -File and the script path, then any parameters:

powershell -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Send-Report.ps1 -City "San Antonio" -Days 30

Swap powershell for pwsh to use PowerShell 7. I ran every command below in a real Command Prompt window, and the two versions don’t always agree on paths, switches and exit codes.

Run a PowerShell script from cmd, step by step

Our test script is Send-Report.ps1. It prints the values it received and exits with code 3 when the city is Nowhere:

param(
    [string]$City = 'Austin',
    [int]$Days = 7,
    [string[]]$Recipients = @('ops@contoso.com'),
    [switch]$Detailed
)
"City: $City | Days: $Days | Recipients: $($Recipients.Count) | Detailed: $Detailed"
if ($City -eq 'Nowhere') { exit 3 }

The param() block at the top declares the parameters, the same way you pass variables to a PowerShell script from inside PowerShell.

  1. Press Windows + R, type cmd and press Enter to open Command Prompt.
  2. Move to the script’s folder with cd, for example cd /d C:\Scripts. You can skip this if you type the full path.
  3. Type powershell -File, the script path and the parameters, then press Enter.
  4. Read the output. The window stays in cmd, so you can run the next command right away.

Here are the three commands I typed in the Scripts folder. The first uses the defaults, the other two pass values:

powershell -NoProfile -ExecutionPolicy Bypass -File .\Send-Report.ps1
powershell -NoProfile -ExecutionPolicy Bypass -File .\Send-Report.ps1 -City "San Antonio" -Days 30
pwsh -NoProfile -ExecutionPolicy Bypass -File .\Send-Report.ps1 -City "San Antonio" -Days 30

Output:

City: Austin | Days: 7 | Recipients: 1 | Detailed: False
City: San Antonio | Days: 30 | Recipients: 1 | Detailed: False
City: San Antonio | Days: 30 | Recipients: 1 | Detailed: False
Run a PowerShell script from cmd in Command Prompt
Command Prompt runs Send-Report.ps1 in Windows PowerShell 5.1 and PowerShell 7

Put double quotes around values with spaces, like “San Antonio”. cmd doesn’t treat single quotes as quotes, so ‘San Antonio’ would arrive as two words.

Start a PowerShell session from cmd instead

If you’d rather work inside PowerShell, type powershell (or pwsh) and press Enter. The prompt changes to PS, and exit takes you back to cmd.

Which switches to add to the powershell command

SwitchWhat it does
-FileRuns a .ps1 file and passes the rest of the line to the script
-CommandRuns the text as PowerShell code (arrays, expressions, several commands)
-NoProfile