Execute A Powershell Script From Command Line

less than a minute read

The most reliable way to execute a PowerShell script from the command line is to call the PowerShell host executable directly and point it at your .Even so, ps1". ps1file using the-Fileparameter — for example,powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\Backup.This single line works from Command Prompt, from a batch file, from Task Scheduler, and from any automation tool, and it is the foundation of nearly every Windows automation workflow you will ever build.

Understanding the Two Host Executables

Before typing anything, you need to know which PowerShell you are actually launching, because the executable name changes the syntax slightly.

  • powershell.exe — Windows PowerShell 5.1, bundled with Windows. Present on every modern Windows machine by default.
  • pwsh.exe —
Out the Door

What People Are Reading

Readers Went Here

If This Caught Your Eye

Thank you for reading about Execute A Powershell Script From Command Line. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home