4

Using PowerShell (version 5.1.17134.228), found some unexpected differences between Get-Module and Get-InstalledModule, in that some modules that I'd expect to be returned by Get-InstalledModule are not.

As an example:

Get-Module -ListAvailable -Name 'Hyper-V'

Get-InstalledModule -Name 'Hyper-V'

Output:

PS C:\> Get-Module -ListAvailable -Name 'Hyper-V'


    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules


ModuleType Version    Name      ExportedCommands
---------- -------    ----      ----------------
Binary     2.0.0.0    Hyper-V   {Add-VMAssignableDevice, Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMGpuPartitionAdapter...}
Binary     1.1        Hyper-V   {Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMHardDiskDrive, Add-VMMigrationNetwork...}


PS C:\> Get-InstalledModule -Name 'Hyper-V'
PackageManagement\Get-Package : No match was found for the specified search
criteria and module names 'Hyper-V'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.5\PSModule.psm1:9125 char:9
+         PackageManagement\Get-Package @PSBoundParameters | Microsoft. ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage

As you can see, the Get-Module command is returning a local path of the Hyper-V modules, so it's definitely installed locally, but Get-InstalledModule cannot find the module.

Is this a bug or have I misunderstood what Get-InstalledModule is meant to do?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
ZenoArrow
  • 697
  • 7
  • 21
  • 3
    `Get-InstalledModule` can only return what `Install-Module` has installed. The Hyper-V cmdlets aren't installed that way, but with `Install-WindowsFeature`. Basically, you wouldn't expect `Get-InstalledModule` to return any "standard" modules. – Jeroen Mostert Nov 07 '18 at 12:18
  • Thanks for the advice Jeroen. Not ideal (as from a user's point of view I doubt it matters how the module was installed), but at least the reason behind the current output is clearer. – ZenoArrow Nov 07 '18 at 13:21
  • I've never used `Get-InstalledModule` :) – Dennis May 31 '23 at 22:05

0 Answers0