Вопрос

I am trying to execute an installation via start-process but i want it to execute as a job so i can execute a few other statements while also being able to check the status of the installation as it runs in the background.

Here is a section of the code i am trying to execute -

$SetupPath = "C:\Test Installs"
# Enclose the path to setup.exe in quotes
$Setup = "`"" + "$SetupPath\setup.exe" + "`""

$command = "{$SetupProcess=" + "Start-process" + " " + `
"$Setup" + " "+ "-ArgumentList" + " " + `
"/config   config.xml" + " " + "-Wait -PassThru" + "}"

# The above command equals-> {$SetupProcess=Start-process "C:\Test Installs\setup.exe" -ArgumentList /config   config.xml -Wait -PassThru}

#Change string to Scriptblock
$ScriptBlock = [Scriptblock]::Create($command) 

$job1 = Start-Job -ScriptBlock $ScriptBlock -Name "SetupJob"

When I run this and try to get back the result via Receieve-Job i only get back the command string I passed via script block. It appears the Start-process command is not executing. Is there something i am missing?

Это было полезно?

Решение

Get rid of the {} in your $command definition. [ScriptBlock]::Create() expects some text in which it will wrap in a scriptblock. You can also simplify this:

$SetupPath = "C:\Test Installs"
# Enclose the path to setup.exe in quotes
$Setup = "`"$SetupPath\setup.exe`""

$command = "SetupProcess = Start-process `"$Setup`" -ArgumentList `"/config config.xml`" -Wait -PassThru"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top