PowerShell Universal Modules

Product: PowerShell Universal
Version: 2.8.3

I had configured my own way to incorporate Modules into PSU prior to it being a feature, and unfortunately used the same folder name. I now have several modules in my PSU repository in the Modules folder, however the built-in modules functionality seems to be broken.

If I add a module using the GUI it does not show up in the GUI, however the folder and module file are created in the Repository. Also, searching for modules using PowerShell gallery doesn’t work at all (searching at the CLI produces results, but not the GUI).

Finally, do you have any plans to support other module sources? We have an internal NuGet repository that we regularly push modules to and it would be nice to be able to install/update directly into PSU using the GUI.

What I did for my internal Modules functionality:

Defined a variable $RepoRoot that points to the root of my repository. Created a $RepoRoot\Modules folder, manually copied modules from my own Modules folder into there and committed them with Git. Then included this bit of code into my scripts:

if ( $env:PSModulePath.IndexOf("$RepoRoot\Modules") -eq -1 ) { $env:PSModulePath = “$RepoRoot\Modules;$env:PSModulePath” }

Are you seeing any errors in the logs or notifications when adding a module? I did add some error handling to in 2.9 to account for modules in that folder that do not match the ModuleName\ModuleVersion\ModuleName.psm1 format produced by PSU.

As for the PS gallery not working, how are you hosting PSU? The problem is that the NuGet provider isn’t installed by default, which we made an attempt to resolve by deploying it ourself, but I’m still getting reports that it isn’t working.

We do have plans to add the ability to define your own package sources. I’ll make sure we have an issue open for it.

So, the search doesn’t even work. I can type a module name in and just nothing happens. Spins for a second and then no output.

Log shows this output when searching:

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.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
2022-03-07 09:38:10.882 -06:00 [WRN] Failed to sync
System.IO.FileNotFoundException: Could not find file 'C:\ProgramData\UniversalAutomation\Repository\Modules\AWS.Tools.Common\4.1.18.0\AWS.Tools.Common.psm1'.
File name: 'C:\ProgramData\UniversalAutomation\Repository\Modules\AWS.Tools.Common\4.1.18.0\AWS.Tools.Common.psm1'
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.File.AsyncStreamReader(String path, Encoding encoding)
   at System.IO.File.InternalReadAllTextAsync(String path, Encoding encoding, CancellationToken cancellationToken)
   at UniversalAutomation.Services.ModulesConfigurationScript.ReadAsync(Boolean initialSync) in D:\a\universal\universal\src\Universal.Server\Services\Configuration\Modules.cs:line 51
   at UniversalAutomation.Services.UniversalConfigurationService.NotifyChange(String fileName) in D:\a\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 143
2022-03-07 09:38:10.944 -06:00 [WRN] Failed to sync
System.IO.FileNotFoundException: Could not find file 'C:\ProgramData\UniversalAutomation\Repository\Modules\AWS.Tools.Common\4.1.18.0\AWS.Tools.Common.psm1'.
File name: 'C:\ProgramData\UniversalAutomation\Repository\Modules\AWS.Tools.Common\4.1.18.0\AWS.Tools.Common.psm1'
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.File.AsyncStreamReader(String path, Encoding encoding)
   at System.IO.File.InternalReadAllTextAsync(String path, Encoding encoding, CancellationToken cancellationToken)
   at UniversalAutomation.Services.ModulesConfigurationScript.ReadAsync(Boolean initialSync) in D:\a\universal\universal\src\Universal.Server\Services\Configuration\Modules.cs:line 51
   at UniversalAutomation.Services.UniversalConfigurationService.NotifyChange(String fileName) in D:\a\universal\universal\src\Universal.Server\Services\UniversalConfigurationService.cs:line 143

However, the nuget provider is installed:

PS C:\ProgramData\PowerShellUniversal> gci 'C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll'


    Directory: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         3/7/2022   9:23 AM         174256 Microsoft.PackageManagement.NuGetProvider.dll

The second two errors seem unrelated, but they came right after the initial error. BTW, the AWS.Tools.Common is a binary module and doesn’t have a PSM1… so it shouldn’t be looking for that file.

The issue you are seeing with the AWS module will be resolved in 2.9. We were assuming that only modules with a very specific format (like the one we generate in PSU) would be in the folder.

As for the NuGet provider…this one has me a bit perplexed. The location looks correct but I’m wondering if it’s because we aren’t calling Import-PackageProvider: Bootstrapping NuGet - PowerShell | Microsoft Docs

What’s even a bit weirder is that the version of PackageManagement we ship with PSU contains the NuGet provider.

I’m going to play around with this. Can you let me know how you are hosting PSU?

It’s just running as a Windows service, no IIS or anything.

Ok. Thanks. I’m going to stand up a new server to see if I can get this to reproduce on my end.