PowerShell ISE Crashes after loading Winforms
When Winforms are used in PowerShell code, the ISE will eventually freeze/crash when idle (after form closed). This can happen as fast as 5 minutes but may take longer, time seems to be random. No issues occur when using Winforms via regular PowerShell console and using other IDEs (such as PowerGUI).
Example code to reproduce:
$Form = New-Object System.Windows.Forms.Form
$Form.DataBindings.DefaultDataSourceUpdateMode = 0
$Form.Text = "My Form"
$Form.AutoSize = $true
$Form.AutoSizeMode = "GrowAndShrink"
$Form.StartPosition = "CenterScreen"
$Form.MaximizeBox = $false
$Form.FormBorderStyle = "FixedSingle"
$Return = $Form.ShowDialog()
Note: It does appear the more form objects added, the more likely to crash, but can happen on code as simple as this.

19 comments
-
Justin Marshall commented
apparently this was acknowledge by MS in support article 943139, searching for this article returns numerous hits but they all show a 404 error so not sure what the state is.
-
Saul Cruz commented
this happens in Windows Server 2016 as well, any workarounds out there?
-
Anonymous commented
Nearly 3 years now and the problem still has no resolution :(
-
Dan commented
Still having this issue when connecting to different O365 services with MFA using Winforms. The code used is the one created and published by Microsoft.
If you're unable to solve the issue with Winforms, would it be possible for you to create new methods of connecting which do not rely on Winforms for managing O365 with Powershell and MFA? Any quick fix for this problem would be highly appreciated.
-
spam commented
Having the same problem on Win10 64 bit with ISE 64 bit.
I Have with none MFA,and with MFA it's crazy
please look this bug -
Sunny Ape commented
Having the same problem on Win10 64 bit with ISE 64 bit. A PS script with a single form with half a dozen objects added will randomly cause ISE to freeze when running the script. Can only force restart ISE with task manager.
Not sure why Dennis says "ISE is MTA", but ISE always runs in STA mode by default. You need to force it into STA mode with the '-sta' switch on launch.
PowerShell version is 5.1.14393.1944
Windows 10 version is 1607, build 14393.1944 -
Dennis commented
ISE is MTA ans Forms must be STA. If you use showdialog() his Parent is ISE(MTA). Use [System.windows.forms.application]::run($form)
-
Dennis commented
Take [System.windows.application]::run($form) instead of $Form.showdialog() and oh Works fine...
-
Joe Pochedley commented
I just started running into this after switching on MFA in my Office 365 account! Really annoying.
-
Muller commented
This issue is systematic and really annoying. I Hope MS will fixes it soon. Iwill really prefer staying using MS integrated editors.
-
Ryan commented
same issue with MFA that Eric is seeing. If i run a powershell script that uses connect-msolservice a popup appears that request login to azure. i login and approve via my cell phone. (MFA) I can run the remainder of my script however if i go idle for a few minutes the ISE window will freeze. I have to close ISE from task manager. I am running Windows 8.1 PS version 5 and MSOnline module version 1.1.166.0
-
Eric commented
Unable to use MFA with Office 365 and Powershell ISE. After enabling MFA for all of our accounts now Powershell ISE freezes for all of our admins. This has been an on-going issue for quite some time.
-
Chris commented
I believe this is also causing the ISE to crash when using the Office 365 MSOnline module (1.1.166.0) with modern authentication and multi-factor authentication, as this pops up a form of sorts to handle the logon. I'm running on Windows 7 pro(x64), and have had this occur with PS 4 + 5 on multiple machines.
-
MarkN commented
Having similar issue Win 10 1607 (14393.321), PS 5.1
Name Value
---- -----
PSVersion 5.1.14393.206
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.206
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1 -
Dan commented
Same issue here. [Voting]::Up
P.S. URL to bcehr's original question on social.technet is below:
-
Anonymous commented
This is still an issue with Powershell ISE in Windows 10.
Please take this serious Microsoft.
It's very annoying. -
Vífill commented
I have the same problem..
-
Edwin Fine commented
This is definitely an issue. To the person in another forum who wrote that non-programmers should not use WinForms in PowerShell, I've been a programmer for 30+ years and I see this issue consistently, ergo, it's not limited to non-programmers.
-
tcox8 commented
I can replicate this. I found the following on the Connect site. You can force the freeze up simply by changing your computer screen resolution or letting the screensaver (with password) occur.