PowerShell for Windows Admins

Dec 6 2017   9:19AM GMT

PowerShell v6: #7 Module paths

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

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.

 

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: