Please feel free to provide feedback or file bugs here.

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.

73 votes
Sign in
(thinking…)
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

bcehr shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

17 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Dan commented  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    Take [System.windows.application]::run($form) instead of $Form.showdialog() and oh Works fine...

  • Joe Pochedley commented  ·   ·  Flag as inappropriate

    I just started running into this after switching on MFA in my Office 365 account! Really annoying.

  • Muller commented  ·   ·  Flag as inappropriate

    This issue is systematic and really annoying. I Hope MS will fixes it soon. Iwill really prefer staying using MS integrated editors.

  • Ryan commented  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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  ·   ·  Flag as inappropriate

    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

  • Anonymous commented  ·   ·  Flag as inappropriate

    This is still an issue with Powershell ISE in Windows 10.
    Please take this serious Microsoft.
    It's very annoying.

  • Edwin Fine commented  ·   ·  Flag as inappropriate

    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.

Feedback and Knowledge Base