Script hangs on using Find-PSResource in PSS 2024

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 months and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
AdamLaFontaine
Posts: 7
Last visit: Mon Jul 15, 2024 8:04 am

Script hangs on using Find-PSResource in PSS 2024

Post by AdamLaFontaine »

Hi All
It seems like Powershell Studio has some Problems when using Find-PSResource.
The Script just hangs and keeps hanging until manual stop.

Steps to reproduce:
1. Creating a new Windows Forms Script (no matter which PWSH Version)
2. Be sure to trust your Repository (for test you can also use PSGallery)
3. Using Find-PSResource with -Respository and -Name Param
4. Script hangs
5. Comment the line with Find-PSResource will make the whole script work again

I tried Powershell Studio 2022, 2023 and 2024 5.8.246.
Console Output (debug):
  1. >> Debugging (Scriptname.psf) Script...
  2. >> Platform: V7 64Bit (STA) (Forced)
  3. >> Analyzing Script (Results in Tools Output panel)...
  4. DEBUG: Reading repository info for 'MyRepoName'
  5. DEBUG: In FindPSResource::ProcessResourceNameParameterSet()
  6. DEBUG: Filtering package name(s) on wildcards
  7. DEBUG: In FindHelper::FindByResourceName()
  8. DEBUG: Parameters passed in >>> Name: 'MyModuleName'; ResourceType: 'None'; VersionRange: ''; NuGetVersion: ''; VersionType: 'NoVersion'; Version: ''; Prerelease: 'False'; Tag: ''; Repository: 'MyRepoName'; IncludeDependencies 'False'
  9. DEBUG: Searching through repository 'MyRepoName'
  10. DEBUG: In FindHelper::SearchByNames()
  11. DEBUG: No version specified, package name is specified
  12. DEBUG: In V3ServerAPICalls::FindName()
  13. DEBUG: In V3ServerAPICalls::FindNameHelper()
  14. DEBUG: In V3ServerAPICalls::GetVersionedPackageEntriesFromRegistrationsResource()
  15. DEBUG: In V3ServerAPICalls::GetResourcesFromServiceIndex()
  16. DEBUG: In V3ServerAPICalls::HttpRequestCall()
  17. DEBUG: Request url is 'https://myrepourl/index.json'
Running the same code on a direct Powershell 7 Console with same Version works flawlessly.

Is there something i miss?

Thanks and best Regards,
Andreas
User avatar
brittneyr
Site Admin
Posts: 1805
Last visit: Fri Nov 08, 2024 11:17 am
Answers: 44
Been upvoted: 34 times

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

Post by brittneyr »

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):
  1. [void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  2. [void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  3.  
  4. $form1 = New-Object 'System.Windows.Forms.Form'
  5. Find-PSResource -Name PowerShellGet -Repository PSGallery
But if I move the Find-PSResource call before the form object, it will run:
  1. [void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  2. [void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  3.  
  4. Find-PSResource -Name PowerShellGet -Repository PSGallery
  5. $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
Brittney
SAPIEN Technologies, Inc.
User avatar
AdamLaFontaine
Posts: 7
Last visit: Mon Jul 15, 2024 8:04 am

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

Post by AdamLaFontaine »

Thanks a lot for testing Brittney.
I think the only workaround in my case is to avoid using Find-PSResource, otherwise it will load too long at the Script startup.
So in this case i want to add the Module via Custom Installer but since my Module has the pwsh7 Requirement, is it possible to install Powershell 7 also direct via Powershell Studio buildt in Functions?

Or is it possible to simply pack a whole Scriptfolder with several Scripts into a Powershell Studio compiled Script and deploy that specific ScriptFolder to a specific location?

Thanks and best Regards,
Andreas
This topic is 3 months and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked