You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-PSResource does not search in user context environment variable PSModulePath #889
PackageManagement, PowerShellGetv2 and PowerShellGet 3.0.18-beta (and prior versions) does not search in directorories specified in user context environmental variable PSModulePath when searching for modules. But at least v3 has a -Path parameter.
Reproduce:
Install Az.Accounts to %LOCALAPPDATA%\Microsoft\PowerShell\Modules by using Save-PSResource.
Make sure said module is not installed any other places specified in $env:PSModulePath.
Or rather any other default locations for PowerShell modules I guess.
Make sure %LOCALAPPDATA%\Microsoft\PowerShell\Modules is specified in HKCU:\Environment\PSModulePath, and that PowerShell loaded it into $env:PSModulePath at start. Should also be seen in [System.Environment]::GetEnvironmentVariable('PSModulePath','User').
Search for installed modules with PowerShellGet\Get-PSResource -Name 'Az.Accounts'. Result: Not found.
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)&&scopeis not null){Environment.GetEnvironmentVariable("PSModulePath",scope.ValueisScopeType.CurrentUser?EnvironmentVariableTarget.User:EnvironmentVariableTarget.Machine);}
I understand it's more complex than that. One must have tests etc.
Is this one up for grabs, or do you not want environment variable PSModulePath to have any say?
Edit: Here's a PowerShellers attempt. 😁
Click to view
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)&&scopeis not null){stringPSModulePath=Environment.GetEnvironmentVariable("PSModulePath",scope.ValueisScopeType.CurrentUser?EnvironmentVariableTarget.User:EnvironmentVariableTarget.Machine);if(string.IsNullOrEmpty(PSModulePath)){psCmdlet.WriteVerbose("Found no value for PSModulePath given the scope.");}else{foreach(stringelementinPSModulePath.Split(Path.PathSeparator)){if(Directory.Exists(element)){if(string.Equals(element.Split(Path.DirectorySeparatorChar).Last(),"Modules",StringComparison.OrdinalIgnoreCase)){psCmdlet.WriteVerbose(string.Format("'{0}' exists, adding it to 'resourcePaths'.",element));resourcePaths.Add(element);resourcePaths.Add(Path.Combine(Directory.GetParent(element).FullName,"Scripts"));}else{psCmdlet.WriteVerbose(string.Format("'{0}' exists but does not match expected pattern, not adding it to 'resourcePaths'.",element));}}else{psCmdlet.WriteVerbose(string.Format("'{0}' does not exist, not adding it to 'resourcePaths'.",element));}}}}
Activity
o-l-a-v commentedon Apr 1, 2024
Here's the responsible code as far as I can see:
PSResourceGet/src/code/Utils.cs
Lines 993 to 1017 in b28fba0
Seems doable to add PSModulePath here?
I understand it's more complex than that. One must have tests etc.
Is this one up for grabs, or do you not want environment variable
PSModulePathto have any say?Edit: Here's a PowerShellers attempt. 😁
Click to view