使用PowerShell(版本5.1.17134.228)发现Get-Module
和Get-InstalledModule
之间存在一些意外的区别,因为我期望Get-InstalledModule
返回的某些模块没有。
例如:
Get-Module -ListAvailable -Name 'Hyper-V'
Get-InstalledModule -Name 'Hyper-V'
输出:
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
如您所见,Get-Module
命令返回的是Hyper-V模块的本地路径,因此肯定是在本地安装的,但是Get-InstalledModule
找不到该模块。
这是错误还是我误解了Get-InstalledModule
的意图?