Windows 10

How to Run PowerShell Script From A Batch File

In this tutorial, we’ll demonstrate how to execute a PowerShell script from within a Windows batch file (.bat) using the PowerShell.exe command. This approach is useful when you need to integrate PowerShell automation into legacy workflows or scheduled tasks that rely on batch scripts.

A batch file is a plain-text file that contains a sequence of commands to be executed by the Windows command interpreter (CMD). By invoking PowerShell.exe from a batch file, you can launch powerful scripts while maintaining compatibility with older systems or toolchains.
 

🛠 How to Run a PowerShell Script from a Batch File

To execute a PowerShell script (.ps1 file) from a batch file, use the following syntax:
The following example run the PowerShell script “c:\path\to\your\powershell/script.ps1”:

Powershell.exe -executionpolicy remotesigned -File  c:\path\to\your\powershell/script.ps1

 
🔍 Parameters Explained:

  • PowerShell.exe — Launches a new PowerShell session.
  • -ExecutionPolicy RemoteSigned — Temporarily overrides the default execution policy to allow the script to run. This setting allows local scripts to run without being digitally signed.
  • -File — Specifies the path to the PowerShell script to execute.
✅ Tip: Always wrap file paths in quotes to avoid issues with spaces in folder names.

 

🔒 About Execution Policies

PowerShell’s execution policy is a safety feature designed to control the conditions under which PowerShell loads configuration files and runs scripts. Common policies include:

  • Restricted – No scripts allowed (default on many systems).
  • RemoteSigned – Requires downloaded scripts to be signed by a trusted publisher.
  • Unrestricted – Runs all scripts; may prompt for permission on downloaded files.

You can check the current policy by running:

Get-ExecutionPolicy

To permanently change it (optional and not recommended for production), run PowerShell as Administrator and execute:

Set-ExecutionPolicy RemoteSigned

 

🧪 Example Batch File

Here’s how to create a simple .bat file that runs your PowerShell script:

@echo off
PowerShell.exe -ExecutionPolicy RemoteSigned -File "C:\path\to\your\powershell\script.ps1"
pause
  • Open Notepad.
  • Paste the code above.
  • Save the file with a .bat extension (e.g., run_script.bat).
  • Double-click the batch file to run your PowerShell script.

 

✅ Conclusion

Running PowerShell scripts from batch files is a straightforward way to bridge the gap between older Windows scripting methods and the more modern, powerful capabilities of PowerShell. This is especially useful for administrators who need to automate tasks across environments or launch scripts via scheduled jobs.
 

Leave a Reply

Your email address will not be published. Required fields are marked *