Can't search the gallery for modules

Maybe. I’m spinning up a new web app to take a look. I double checked and the NuGet package provider is being deployed so it certainly could be loading the wrong package management module for some reason. I would think it would be loading the newer one…

1 Like

Yep, looks like I have that on my App Service instance:

1 Like

Yeah something is happening with the mismatch of PowerShellGet versions (ugh!!)

I tried this.

Import-Module PowerShellGet -RequiredVersion 2.2.5
Find-Module Universal
Get-Module

And it still loads the old version of PSGet.

What’s interesting is that I’m able to run the same script in the Windows PowerShell environment without problem. The issue is the integrated environment is what is responsible for installing modules…

Still toying with it…

1 Like

Ok. Have a work around for now.

This is how I got it to work. Created a script that removes the Windows PowerShell paths from the $Env:PSModulePath

[Environment]::SetEnvironmentVariable("PSModulePath", 'D:\local\UserProfile\Documents\PowerShell\Modules;PowerShell\Modules;D:\Program Files\PowerShell\Modules;D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\;D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\;D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Storage\;D:\Program Files\Microsoft Message Analyzer\PowerShell\D:\home\site\wwwroot\Modules;D:\home\site\wwwroot\Modules;;D:\home\site\wwwroot\..\Modules;D:\home\Data\PowerShellUniversal\Repository\Modules; ', 'Process')

Then, I setup a trigger to run at server startup for this script. I then restarted the web app.

Finally, I tried to install some modules.

This worked!

Now that I have these modules installed, I’ll figure out how to setup AZ Key Vault in PSU.

1 Like

I wonderf if I can set the PSModulePath environment variable from the Azure App Service environment config. I might try that first - could be easier than setting up the script and trigger etc. Or did you try that as well?

Edit: Ah, invalid variable name. Won’t let you override it from the Azure portal.

Edit 2: SUCCESS! Thanks so much, Adam. This and the secrets thing were our two shopstoppers, so we’re almost there. Do you think there’s a fix for this that doesn’t involve the custom script in a future version?

1 Like

Yeah. I think we can force an import of the specific version of this module when the service loads. I’m gonna seen if I can sneak that into 2.6.1 but I’ll let you know if i run into any snags. I’ll play with the Az Key Vault stuff tomorrow and let you know if I can get a vault up and running. It’ll likely use a start up script too but hopefully won’t be too bad!

2 Likes

Just set this up with a similar startup script in our app service deployment - really great stuff, I’d actually given up even thinking this was possible with the deployed app services file-system being so read-only.

Awesome stuff yet again, Adam.

Leads me to a new question though - we have a private nuget repository using an Azure DevOps artifact feed with all our own modules - is there anyway to use a custom repo on top of the Powershell Gallery currently or anything planned for the future?

We don’t support this for the moment but have it in the backlog: NuGet Feed for local Module repository · Issue #476 · ironmansoftware/issues · GitHub

1 Like

Ah, brilliant - I’ll keep my eyes peeled :slight_smile:

@adam We might have a regression in the latest versions. On 2.8.1 if I try to search the gallery for a module, it spins for a second and says no results, but the log contains this exception:

System.Management.Automation.CommandNotFoundException: The 'Find-Module' command was found in the module 'PowerShellGet', but the module could not be loaded. For more information, run 'Import-Module PowerShellGet'.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at Universal.Server.Services.ModuleDiscoveryService.FindModule(String searchText) in D:\a\universal\universal\src\Universal.Server\Services\ModuleDiscoveryService.cs:line 36

Any ideas?

I tried running Find-Module from the integrated terminal and was met with this error:

[ERROR] The term 'PackageManagement\Get-PackageProvider' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
[ERROR] The term 'PackageManagement\Get-PackageProvider' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
[ERROR] Exception calling "ShouldContinue" with "2" argument(s): "A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet provider to publish an item to NuGet-based repositories. The NuGet provider must be available in 'D:\Program Files\PackageManagement\ProviderAssemblies' or 'D:\local\LocalAppData\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?"
[ERROR] NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.

I am seeing this alert on a new installation of the docker container. Running 2.8.3.

Here are my modules:

    Directory: /opt/microsoft/powershell/7/Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   1.2.5                 Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path…}
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core      {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ConvertFrom-SecureString…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias, New-Alias…}
Script     1.4.7                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script     2.0.5                 PSDesiredStateConfiguration         Core      {Configuration, New-DscChecksum, Get-DscResource, Invoke-DscResource}
Script     2.1.0                 PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-PSReadLineOption…}
Binary     2.0.3                 ThreadJob                           Desk      Start-ThreadJob

Here are my package providers:

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            2.2.5.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, AcceptLicense, Publ…

Here is the relevant log entry:

2022-02-22 21:09:26.015 +00:00 [ERR] Error while searching for module
System.Management.Automation.CmdletInvocationException: NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
 ---> System.InvalidOperationException: NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.Runspaces.Pipeline.Invoke()
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at Universal.Server.Services.ModuleDiscoveryService.FindModule(String searchText) in D:\a\universal\universal\src\Universal.Server\Services\ModuleDiscoveryService.cs:line 39
1 Like

Have you had a chance to look at this one, @adam? Sounds like it might not just be me that can’t search for modules since updating to 2.8.1. We’re on 2.8.3 now and still having the same issue.

We have an issue overall with the integration to PackageManagement. Seems to work when you have the provider installed manually but it doesn’t work when installed as a service or in an Azure Web App. Still an active issue. Recently, had some discussion here about it.

Ah bummer. It was working in a previous version! I will keep an eye out for the official 2.9 release.

That’s weird. We aren’t doing anything different in terms of how we look up modules so I’m surprised that it used to work for you. The difference in more recent versions is that we include the NuGet package provider DLL but that didn’t solve it, it seems.

You and I got it working earlier in this thread. Your suggestion of modifying the module path had fixed it. But something in 2.8 broke it again.

:smiley:

OK I just updated to 2.9.0 and the issue is still there.

To recap, my “on startup” script has this (which made it work prior to 2.8):

# Remove classic PowerShell module path
[Environment]::SetEnvironmentVariable("PSModulePath", 'D:\local\UserProfile\Documents\PowerShell\Modules;D:\Program Files\PowerShell\Modules;D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\;D:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Storage\;D:\Program Files\Microsoft Message Analyzer\PowerShell;D:\home\site\wwwroot\Modules;D:\home\site\wwwroot\..\Modules;D:\home\Data\PowerShellUniversal\Repository\Modules; ', 'Process')

… but when searching for modules I get no results and this in the log:

System.Management.Automation.CommandNotFoundException: The 'Find-Module' command was found in the module 'PowerShellGet', but the module could not be loaded. For more information, run 'Import-Module PowerShellGet'.
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at Universal.Server.Services.ModuleDiscoveryService.FindModule(String searchText) in D:\a\universal\universal\src\Universal.Server\Services\ModuleDiscoveryService.cs:line 36

Sorry about the miscommunication on this.

Spinning up my Azure stuff to see if I can figure out a work around. I’ll make sure a fix for this gets into 2.9.1

1 Like