Monthly Archive

Categories

PowerShell v6: #7 Module paths

There is a very significant gap between the functionality available in PowerShell v6 as opposed to PowerShell v5.1. In part this is due to the underlying version of .NET but mainly to the defined module paths in the two versions.

In PowerShell v5.1 I have:

PS>  $env:PSModulePath -split ';'
C:\Scripts\Modules
C:\Users\Richard.MANTICORE\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

 

In PowerShell v6 I have

PS C:\scripts> $env:PSModulePath -split ';'
C:\Users\Richard.MANTICORE\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6.0.0-rc\Modules

 

The vast majority of the module supplied with PowerShell v5.1 reside in C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules which PowerShell v6 can’t see.

 

Unless you add it in yourself

$env:PSModulePath = $env:PSModulePath + ';C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules'

 

I’ve appended the PowerShell v5.1 modules to the PowerShell v6 module path.

 

There’s still no guarantee that the modules will work – it depends on the module code and if it accesses .NET classes that aren’t available in .NET core.

 

You’ll have to use trial and error to determine what works. For instance:

Get-NetAdapter
Get-Volume
Get-Partition

all work. BUT they’re from CDXML modules based on CIM classes not binary modules. As a rule thumb I’d expect the CIM based modules to just work. Binary module will definitely be trial and error.

Comments are closed.