Quantcast
Channel: SAPIEN Forums
Viewing all articles
Browse latest Browse all 512

PowerShell • Re: Script hangs on using Find-PSResource in PSS 2024

$
0
0
Based off my tests, I have not been able to get Find-PSResource to work after the initialization of any form object.
For example, the following code will hang regardless of where I run it (Console, PowerShell Studio, etc):

Code:

[void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
[void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')

$form1 = New-Object 'System.Windows.Forms.Form'
Find-PSResource -Name PowerShellGet -Repository PSGallery
But if I move the Find-PSResource call before the form object, it will run:

Code:

[void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
[void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')

Find-PSResource -Name PowerShellGet -Repository PSGallery
$form1 = New-Object 'System.Windows.Forms.Form'

We have seen similar behavior with other commands such as Connect-ExchangeOnline. Most Azure and "online" products require connection and loading of modules before you display any form. This is most likely due to the "single-threaded" nature of PowerShell. Most APIs rely on being able to control a thread completely until the connection operation is completed. Forms and GUIs tend to disrupt this and cause failures in online connective processes. While I'm aware this is not exactly the same, there seems to be a similar thread issue happening which results in the script hanging.

As this is an issue with Find-PSResource, you can report this, but I'm not sure it can or will be addressed by Microsoft:
https://github.com/PowerShell/PSResourceGet/issues

Statistics: Posted by brittneyr — Mon Jul 08, 2024 1:57 pm



Viewing all articles
Browse latest Browse all 512

Trending Articles