Aug 15 2023 10:31 PM
I was testing a colleague's small script which lists VM snapshots from our vCenters, and it uses a Windows Form to get the vCenter name, username & password. It then logs into the vCenter and extracts the required info.
In a PowerShell command line, it works perfectly. In the ISE, the code runs fine until it completes then after about 10 seconds, the ISE freezes. I tried the same code on other Windows servers in our environment and the same happened.
To test if it was code related or not, I have a script which Get-Credential to ask the user for logon details so I modified the code to create a form with the username & password details using labels & textboxes with an OK button. As soon as I ran the code, it froze the ISE. Again if run from the PowerShell command line, works fine.
I tried adding the following to the scripts which did not help:
Add-Type -AssemblyName Microsoft.VisualBasic,
PresentationCore,
PresentationFramework,
System.Drawing,
System.Windows.Forms,
WindowsBase,
WindowsFormsIntegration
[System.Windows.Forms.Application]::EnableVisualStyles()
I'm using $Form.Dispose()
Linked references:
https://community.spiceworks.com/topic/1367945-powershell-ise-hanging-when-using-forms
Does anyone know of any fixes for this situation?
Aug 16 2023 07:26 AM
Aug 21 2023 10:51 AM - edited Sep 03 2023 02:24 AM
Any update ?