Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output Handling in ManagementExtension-Samples/IntunePSTemplate.ps1 #11

Open
persident opened this issue Oct 21, 2021 · 0 comments
Open

Comments

@persident
Copy link

persident commented Oct 21, 2021

For the x86 -> x64 context switch, the IntunePSTemplate.ps1 sample sets the RedirectStandardOutput property for the ProcessStartInfo object to $true, but does not consume the StandardOutput. This can cause the new x64 child process to hang indefinitely:

>> (..) When the child process writes enough data to fill its redirected stream, it is dependent on the parent. The child process waits for the next write operation until the parent reads from the full stream or closes the stream. (..) <<
Source: ProcessStartInfo.RedirectStandardOutput Property

When the StandardOutput is not consumed by the parent script, the $pinfo.RedirectStandardOutput should be set to $false.

There is another issue: $exitCode = $p.ExitCode gets called without waiting for the child process to exit. Therefore, $exitCode will come back as $NULL most of the time. Better code would look like this:

$stderr = $p.StandardError.ReadToEnd()
$p.WaitForExit()
$exitCode = $p.ExitCode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant