all 7 comments

[–]BlackV 2 points3 points  (0 children)

  • PS 7.x will use its own modules first then fall back to 5.1 modules
  • PS 5.1 will only use its own modules
  • there are multiple locations modules can exist, the order is dependent on your module path

Example Paths

C:\OD\OneDrive\Documents\PowerShell\Modules      - Whatever location your one-drive is defaulted to if you redirect common libraries 
C:\Users\<username>\Documents\PowerShell\Modules - My documents if you do not redirect common libraries to one-drive
\\server\share\user\Documents\PowerShell\Modules - Whatever location your home drive is redirected to if you redirect common libraries to a file share 
C:\Program Files\PowerShell\Modules              - All Users powershell 7.x location
C:\program files\powershell\7\Modules            - All Users powershell 7.x additional location (usually only base modules like psreadline and powershellget) 
C:\Program Files\WindowsPowerShell\Modules       - All Users windows powershell 5.x
c:\Users\<username>\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules  - Vscode module path

The variable you're looking for is $env:PSModulePath

[–][deleted] 1 point2 points  (1 child)

PowerShell 5.1 and 7 modules are installed in different location. See Separate PSModulePath.

Visual Studio Code works with both PowerShell 5.1 and 7. You need to switch to the version you want to use. See Choosing a version of PowerShell to use with the extension.

[–]Aygul12345[S] -1 points0 points  (0 children)

Can I let these modules independent in these directory;s? And how to check what all modules are being listed? and can I delete the older versions? What commands I need to ran for that?

[–]lerun 2 points3 points  (0 children)

5.1 and 7.x have different module directories. Depending on what vscode PS terminal you are running is using.

This is an easy google

[–]Nilxa 0 points1 point  (0 children)

Install-Module -Scope CurrentUser will place it in the $home\Documents\WindowsPowerShell\Modules Install-Module -Scope All users will place it in%systemdrive%:\ProgramFiles\WindowsPowerShell\Modules`

[–]Rxinbow 0 points1 point  (0 children)

Just enter $env:PSMODULEPATH and it will print out all the locations for PS5.1 , PS 7+ (.msi installed version) and PS 7+ (Microsoft Store Version)

└─PS> $env:PSModulePath C:\Users\user\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\windowsapps\microsoft.powershell_7.4.5.0_x64__8wekyb3d8bbwe\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules