To run a PowerShell script from a batch file, you can use the powershell.exe command to execute the script. Here’s how you can do it:
Syntax:
powershell.exe -ExecutionPolicy Bypass -File “C:\path\to\your\script.ps1”
Steps:
1. Create a batch file (.bat):
Open Notepad or any text editor.
Write the following command in the file:
powershell.exe -ExecutionPolicy Bypass -File “C:\path\to\your\script.ps1”
Replace C:\path\to\your\script.ps1 with the actual path to your PowerShell script.
2. Save the file as a .bat file, for example, run_script.bat.
3. Run the Batch File:
Double-click the .bat file to execute the PowerShell script.
Explanation:
-ExecutionPolicy Bypass allows the script to run even if PowerShell’s execution policy is set to restrict scripts.
-File specifies the path to the PowerShell script you want to run.