"Start-Process -NoNewWindow" within a Start-Job?
A little late, but for people still having issues with this specific error message, one fix for this example is to use -WindowStyle Hidden
instead of -NoNewWindow
, I've had -NoNewWindow
appear to get ignored a lot of the time and cause it's own problems.
But for this specific error that seems to come from using Start-Process
with various executables, I have found the solution that seems to work consistently is by redirecting the output, as it is the output that comes back appears to cause the problem. Unfortunately though that does result in writing to a temporary file and cleaning it up.
As an example;
Start-Job -ScriptBlock { # Create a temporary file to redirect output to. [String]$temporaryFilePath = [System.IO.Path]::GetTempFileName() [HashTable]$parmeters = @{ 'FilePath' = 'cmd'; 'Wait' = $true; 'ArgumentList' = @('/c', 'echo'); 'RedirectStandardOutput' = $temporaryFilePath; } Start-Process @parmeters | Out-Null Start-Process -FilePath cmd # Clean up the temporary file. Remove-Item -Path $temporaryFilePath}Get-Job | Wait-Job | Receive-JobGet-Job | Remove-Job
Hopefully this helps.