PowerShell / WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
Other
137 stars 33 forks source link

Remove 'Program Files' module path from Add-WindowsPSModulePath function #29

Closed sethvs closed 5 years ago

sethvs commented 6 years ago

Since ${env:programfiles}\WindowsPowerShell\Modules is in PSModulePath machine environment variable, it should not be added twice.

markekraus commented 6 years ago

Hi @sethvs! That path is not included by default. Here is what I see in $env:PSModulePath on PowerShell Core 6.0.2:

C:\Users\marke\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\6.0.2\Modules
sethvs commented 6 years ago

I mean it is present in:

[System.Environment]::GetEnvironmentVariable("psmodulepath", [System.EnvironmentVariableTarget]::Machine)

C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

https://github.com/PowerShell/WindowsCompatibility/blob/779efdbabf5ed07601bb1b3742677de10d8a4c08/WindowsCompatibility/WindowsCompatibility.psm1#L698

So when you use Add-WindowsPSModulePath function, the result is that C:\Program Files\WindowsPowerShell\Modules is included twice:

[6.1.0-preview.3] PS C:\Folder> $env:PSModulePath -split ';'

C:\Users\User\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6-preview\Modules

[6.1.0-preview.3] PS C:\Folder> Add-WindowsPSModulePath
[6.1.0-preview.3] PS C:\Folder> $env:PSModulePath -split ';'

C:\Users\User\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6-preview\Modules
C:\Users\User\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
markekraus commented 6 years ago

Hmmm... I think it is fine to keep it in there. It doesn't hurt anything, but if someone has modified their PSModulePath env var to no no longer include that path, then it would be missing.

markekraus commented 6 years ago

I guess a better way would be to paths only if they don't already exist in PSModulePath.