Sometimes, To automate the tasks, You need to call powershell scripts from batch files.

batch files are dos programming scripting files that contains script files with extension .bat or .cmd.

powershell offers scripting to automate powerful tasks, It has own script files with extension .ps1.

Let’s see how to call powershell scripts from bat files or command scripts.

First, Create a batch file. test.bat file.

You can use either -File or -Command option to powershell tool

Use, powershell command inside a batch script file

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'e:\run.ps1'"

or

PowerShell -NoProfile -ExecutionPolicy Bypass -File "e:\run.ps1"

-NoProfile: option allow you to skip loading powershell user profile.

-ExecutionPolicy Bypas: this options allow you to bypass execution policy if execution policy is set to Restricted.

-File option allows to pass script file to execute.

Alternatively, -Command option allows to execute commands or scripts to powershell command. It contains enclosed optional {}, preceded by an & and a script file.