invoke-expression problem


i have question using invoke-expression. have script works fine of time. on occasion, command run invoke-expression 'jumps out'. say, runs command in background. example,

$com10 = "cmd /c miis_staged_run step 10"
$com11 = "cmd /c miis_staged_run step 11"

invoke-expression $com10
invoke-expression $com11

i have expected first expression have completed before going on second expression. on occasion (especially if takes long time on 30 minutes) $com11 start running before $com10 has finished. there way ensure first 1 finishes before starting second one? if matters, miis_staged_run .net program.

thanks -- dean

the code below wil fire cmd.exe , notepad.exe. notepad.exe childprocess of cmd.exe. code below continue if both notepad , cmd.exe have finished.

$process = new-object system.diagnostics.process

$si = new-object system.diagnostics.processstartinfo
$si.filename = "cmd.exe"
$si.arguments = "/k start notepad.exe"

$process.startinfo = $si
$process.start()
$processid = $process.id
$process.waitforexit()

while (get-wmiobject win32_process -filter "parentprocessid = $processid")
{
 sleep -seconds 1
}



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2