Explanation
In PowerShell
command Get-Module -ListAvailable
should give you (MS Docs link) all modules in paths listed in the $PSModulePath
environment variable. But that is not full story. What I figured out so far is that directory name in which module manifest is located must be the same as module name. It can optionally include version as additional folder level.
For example these modules are returned:
C:\Program Files\WindowsPowerShell\Modules\Azure.Storage\4.6.0\Azure.Storage.psd1
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\NetTCPIP.psd1
Even that is not complete story. I have these modules on my computer, located in directory list in $PSModulePath
, but they do not appear in Get-Module -ListAvailable
results.
But, these module manifests are not listed as avaialable modules:
C:\Users\iiric\Documents\PowerShell\Modules\Az.KeyVault\2.1.0\SecretManagementExtension\SecretManagementExtension.psd1
C:\Program Files\WindowsPowerShell\Modules\Azure\5.1.2\ExpressRoute\ExpressRoute.psd1
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\AppLocker\AppLocker.psd1
Note that this is not related to paths. I am getting back module Az.KeyVault version 2.1.0 just fine.
Question
How exactly module discovery is working in PowerShell? Is it described somewhere in more technical details?
Additional hints
Based on source code analysis, I saw some kind of results filtering based on edition and other properties.
Also, what I am suspecting is that Get-Module
once it finds some module, it is not searching inside its subdirectories. However, I was not able to find this documented.
PSModulePath
PS > $env:PSModulePath -split ';'
C:\Users\iiric\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer
C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell
c:\Users\iiric\.vscode-insiders\extensions\ms-vscode.powershell-2020.6.0\modules