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—