Most of the time, you run Windows batch files using the Command Execution Method, which replicates running them in a command prompt window (cmd.exe). But, what if you need to perform additional processing within the same job and you are running that batch processing in PowerShell? You have several methods to launch Windows batch files from within PowerShell using these methods:
Running.BAT or.CMD files in minimized mode. To run a batch file in a minimized window state, follow these steps: Create a shortcut to the.BAT or.CMD file. To do so, right click on the file, click Send To, Desktop (create shortcut) Right click on the shortcut and choose Properties; In the Run: drop down, choose Minimized; Click OK.
- Run a batch file as administrator. To run a batch file as administrator of the computer, you need to mention the path of the batch file in the place of command in the runas syntax. For example, to run the batch file located at c: data mybatchfile.bat, you need to run the below command. Runas /user:administrator C: data mybatchfile.bat.
- The batch file doesnt run as admin and based on my research it can't auto run as admin. My idea is to move the program install batch script to a separate folder and create a new batch script for the startup folder that will force the original batch file to run as administrator.
Run Batch File As Administrator Windows 10
You can start a command procedure from PowerShell with the following code. Replace the path and file with your own information.
Once you’ve called your batch file, you can customize it to the task at hand. For example…
If you want to capture the output of the .bat file, you can use:
Run Batch File As Administrator Automatically
If you want to start a process with your .bat file, you can use the PowerShell start-process cmdlet:
And, if you if you want to control cmd.exe, you can use this:
The start-process cmdlet is a standard PowerShell cmdlet, so anyone can use it. JAMS users leverage it regularly and combine it with JAMS specific cmdlets in our PowerShell Scheduler to add intelligent automation to batch files.