MScholtes/TechNet-Gallery

New Window When Powershell Job Started

ThinkpadClock opened this issue · 7 comments

Hello,
Despite which combination of flags I use when compiling my ps1 file (that uses WPF for a GUI), whenever I create a PowerShell job (Start-Job), a new window pops up. The window remains blank, however, and does not disappear right away. Not using -noConsole prevents any new unwanted windows from popping up but then I am stuck with a PowerShell window running while my application runs. Is there a way to stop these windows from showing up?

Hello ThinkpadClock.

what is the script doing in the "Start-Job" command?

Greetings

Markus

Here is one of the scriptblocks:
$serviceblock = {
$tempinfo = Get-CimInstance -Class "Win32_Service" | Select-Object Name, StartMode, State, ProcessId, Status, DisplayName
Write-Output $tempinfo
}

Here's another:
$saveblock = {
param ($log)
$datestring = Get-Date -Format "MM-dd-yyyy-HH-mm-ss"
New-Item -Path "C:\Temp\Logs$datestring.txt" -ItemType File -Force
$log | Out-File "C:\Temp\Logs$datestring.txt"
Write-Output "Log saved to C:\Temp\Logs"
}

upon further testing the saveblock job does not actually create a new blank window like the serviceblock does.

Update: New blank windows are also popping up when Get-CimInstance commands are called without sticking them into a PowerShell job. Running Clear-DnsClientCache produces the same issue but when replaced with ipconfig /flushdns (which is an equivalent command) there is no problem.

Hello Thinkpadclock,

I guess I know what's happening: there is a bug in PS2EXE handling simultanous progress bars. I will fix this with a new release of PS2EXE in a few days.

Until then you can workaround it with disabling progress bars through the expression

$ProgressPreference = 'SilentlyContinue'

at the beginning of your script.

Greetings

Markus

Yes, that has solved the problem!

Thanks Markus!

Hello Thinkpadclock,

the bug was fixed with version 0.5.0.23 of PS2EXE I released today.

Greetings

Markus