start a .exe in the background with parameters in a powershell script start a .exe in the background with parameters in a powershell script powershell powershell

start a .exe in the background with parameters in a powershell script


The job will be another instance of PowerShell.exe and it will not start in same path so . won't work. It needs to know where storage.exe is.

Also you have to use the arguments from argumentlist in the scriptblock. You can either use the built-in args array or do named parameters. The args way needs the least amount of code.

$block = {& "C:\full\path\to\storage\bin\storage.exe" $args}start-job -scriptblock $block -argumentlist "-f", "C:\full\path\to\storage\conf\storage.conf"

Named parameters are helpful to know what what arguments are supposed to be. Here's how it would look using them:

$block = {    param ([string[]] $ProgramArgs)    & "C:\full\path\to\storage\bin\storage.exe" $ProgramArgs}start-job -scriptblock $block -argumentlist "-f", "C:\full\path\to\storage\conf\storage.conf"