(Start-Process) vs. (New-Object System.Diagnostics.Process)
Posted: Mon Jan 18, 2016 6:01 am
Hi,
from within a jobscript, when I create a process using and then start it, it works fine and the process I create (psexec) start within context of PS Studio:
BUT when I start a process using start-process, PSEXEC starts out of PSStudio context and thus the job ends without waiting for the actual psexec process to end:
Is this behavior intended? Why does start-process create the psexec process thread out of PSStudio context?
Thanks for insight.
Thomas
from within a jobscript, when I create a process using
- New-Object System.Diagnostics.Process
- -JobScript { `
- param ($Station,
- $Package,
- $Version)
- $installinfo = New-object System.Diagnostics.ProcessStartInfo
- $installinfo.CreateNoWindow = $true
- $installinfo.UseShellExecute = $false
- $installinfo.RedirectStandardOutput = $true
- $installinfo.RedirectStandardError = $true
- $installinfo.FileName = "$env:TLS_STORE\sysinternals\psexec.exe"
- $installinfo.Arguments = @("-accepteula -s \\$($station) cscript C:\GLOW\TLS\install.vbs /p:$Package /v:$Version")
- $install = New-Object System.Diagnostics.Process
- $install.StartInfo = $installinfo
- [void]$install.Start()
- $install.WaitForExit()
- return $install,$Package,$Station
- }
- -JobScript { `
- param ($Station,
- $Package,
- $Version)
- $install = Start-Process "$env:TLS_STORE\sysinternals\psexec.exe" -ArgumentList "-accepteula -s \\$($Station) cscript C:\GLOW\TLS\install.vbs /p:$Package /v:$Version" -Wait -NoNewWindow -PassThru
- return $install,$Package,$Station
- }
Thanks for insight.
Thomas