PSModulePath no longer works in v5; I am forced to use Import-Module

Hello,

I upgraded from v4 to v5, and now I have to import all the modules in my scripts using “Import-Module.” Previously, it worked with the $PSModulePath environment variable.
I don’t understand how to avoid having to use “Import-Module” anymore.

I’m using the PowerShell 7 environment with “C:\Program Files\PowerShell\7\pwsh.exe.”
The modules are located in “C:\Program Files\PowerShell\7\Modules.”
Here is my $PSModulePath environment variable:

$env:PSModulePath -split ‘;’ —>
C:\Users\admin-user\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
C:\Program Files\PowerShell\7\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\Universal\Modules

In the environments, I added the module path, but it still doesn’t work. I even specified the module path in “Modules to Import” in the environment, but still nothing.

Does anyone know why I’m experiencing this behavior?

Thank you very much.

Are you printing that environment variable in your script that is running in PSU? Or are you looking at the variable from a PS terminal? I mainly ask because PSU does do some messing with the PSModulePath.

That said, it should never be removing the C:\Program Files\PowerShell\7\Modules path so, if it’s not there, then we need to investigate this.

Are these your own custom modules or are they other ones you rely on?

This is the PSModulePath from a PS Terminal.

I use modules imported from PSGallery like AzureAD or MSOnline.

When running the PSModulePath command from PSU, I get:
C:\Program Files (x86)\Universal\Modules
C:\Users\ServiceAccount\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
C:\Program Files\PowerShell\7\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\Universal\Modules
C:\ProgramData\UniversalAutomation\Repository\Modules

That’s very strange. With Microsoft.Graph, the module is automatically imported, but not with MSOnline.

When I try to install MSOnline from PSU under “Platform > Module > Repositories > PSGallery,” the module doesn’t install because the “install” checkbox remains white. Whereas for Microsoft.Graph, the checkbox is greyed out.