Reputation: 1815
I load PowerShell 5 (classic PowerShell). Now I call Get-Module
. This is the result.
PS C:\Program Files (x86)\MSBuild> Get-Module PackageManagement | Select ModuleType, Version, Name, ModuleBase
ModuleType Version Name ModuleBase
---------- ------- ---- ----------
Script 1.4.7 PackageManagement C:\program files\powershell\7\Modules\PackageManagement
Binary 1.0.0.1 PackageManagement C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.0.0.1
It finds the PowerShell 7 module first. How can I prevent that, when I'm in PowerShell 5 I only want to see PowerShell 5.
But as far as I understand $env:PSModulePath
is global and similar for both PowerShells.
Is there a trick to prevent PowerShell 5 from finding Modules for 7?
Upvotes: 0
Views: 855
Reputation: 1723
Powershell v5 included powershell core. The Powershell team has wisely decided to open up powershell and .net and make them cross platform compatible. With the release of Powershell v5 a very important distinction was made. The project was split in two, there's Windows Powershell, and Powershell.
The last real development on Windows Powershell (PoSh) was v5. Powershell (pwsh), which is built on the cross platform .net core, is where all future Powershell development is and will be made.
Having said that, if you don't want modules written in the current standard, uninstall them. You can use Uninstall-Module -Name $name -Version $version
to remove it from your system. That will prevent you from seeing it and will remove it from your machine.
Now, if you want to leave them, but only see the one's written for Windows Powershell run this command (Note: tweak the version number as needed):
Get-Module | Where PowershellVersion -le 5.0.0
I'd encourage you not to do this, as knowing what is available for current architecture is important. But alas, that's your decision.
Upvotes: 1