vmware
PowerShell
vSphere
PowerCLI

PowerShell 6.0でPowerCLI 10.1を起動できない

問題

PowerShell 6.0.2でPowerCLI 10.1.0.8403314を使おうとすると、VMware.VimAutomation.Srm module is not currently supported on the Core edition of PowerShell.というエラーになる。

PS C:\usr\powershell> (Get-InstalledModule -Name VMware.PowerCLI)

Version         Name             Repository  Description
-------         ----             ----------  -----------
10.1.0.8403314  VMware.PowerCLI  PSGallery   This Windows PowerSh...

PS C:\usr\powershell> Import-Module VMware.PowerCLI
Import-Module : VMware.VimAutomation.Srm module is not currently supported on the Core edition of PowerShell.
At line:1 char:1
+ Import-Module VMware.PowerCLI
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (VMware.VimAutom... of PowerShell.:String) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : VMware.VimAutomation.Srm module is not currently supported on the Core edition of PowerShell.,Microsoft.PowerShell.Commands.ImportModuleCommand

対処方法

手順

「not currently supported on the Core edition of PowerShell」となるモジュールが読込対象から外れるように、VMware.PowerCLIモジュールのマニフェストファイルVMware.PowerCLI.psd1を修正する。

まずPowerShellコマンドラインインターフェース上で以下を実行して、該当ファイルのあるディレクトリを開く。

PS C:\usr\powershell> start (Get-InstalledModule -Name VMware.PowerCLI).InstalledLocation

エクスプローラーでVMware.PowerCLI.psd1のあるディレクトリが開かれる。任意のエディタでこのファイルを開き、下記の箇所を探す。

RequiredModules = @(
@{"ModuleName"="VMware.VimAutomation.Sdk";"ModuleVersion"="10.1.0.8342078"}
@{"ModuleName"="VMware.VimAutomation.Common";"ModuleVersion"="10.1.0.8342134"}
@{"ModuleName"="VMware.Vim";"ModuleVersion"="6.7.0.8343295"}
@{"ModuleName"="VMware.VimAutomation.Core";"ModuleVersion"="10.1.0.8344055"}
@{"ModuleName"="VMware.VimAutomation.Srm";"ModuleVersion"="10.0.0.7893900"}
@{"ModuleName"="VMware.VimAutomation.License";"ModuleVersion"="10.0.0.7893904"}
@{"ModuleName"="VMware.VimAutomation.Vds";"ModuleVersion"="10.1.0.8344219"}
@{"ModuleName"="VMware.VimAutomation.Vmc";"ModuleVersion"="10.0.0.7893902"}
@{"ModuleName"="VMware.VimAutomation.Nsxt";"ModuleVersion"="10.1.0.8346947"}
@{"ModuleName"="VMware.VimAutomation.vROps";"ModuleVersion"="10.0.0.7893921"}
@{"ModuleName"="VMware.VimAutomation.Cis.Core";"ModuleVersion"="10.1.0.8377811"}
@{"ModuleName"="VMware.VimAutomation.HA";"ModuleVersion"="6.5.4.7567193"}
@{"ModuleName"="VMware.VimAutomation.HorizonView";"ModuleVersion"="7.1.0.7547311"}
@{"ModuleName"="VMware.VimAutomation.PCloud";"ModuleVersion"="10.0.0.7893924"}
@{"ModuleName"="VMware.VimAutomation.Cloud";"ModuleVersion"="10.0.0.7893901"}
@{"ModuleName"="VMware.DeployAutomation";"ModuleVersion"="6.7.0.8250345"}
@{"ModuleName"="VMware.ImageBuilder";"ModuleVersion"="6.7.0.8250345"}
@{"ModuleName"="VMware.VimAutomation.Storage";"ModuleVersion"="10.1.0.8313015"}
@{"ModuleName"="VMware.VimAutomation.StorageUtility";"ModuleVersion"="1.2.0.0"}
@{"ModuleName"="VMware.VumAutomation";"ModuleVersion"="6.5.1.7862888"}
)

該当箇所を以下で置き換える。いくつかの行が、先頭に#を挿入され、コメント化されている。

RequiredModules = @(
@{"ModuleName"="VMware.VimAutomation.Sdk";"ModuleVersion"="10.1.0.8342078"}
@{"ModuleName"="VMware.VimAutomation.Common";"ModuleVersion"="10.1.0.8342134"}
@{"ModuleName"="VMware.Vim";"ModuleVersion"="6.7.0.8343295"}
@{"ModuleName"="VMware.VimAutomation.Core";"ModuleVersion"="10.1.0.8344055"}
#@{"ModuleName"="VMware.VimAutomation.Srm";"ModuleVersion"="10.0.0.7893900"}
#@{"ModuleName"="VMware.VimAutomation.License";"ModuleVersion"="10.0.0.7893904"}
@{"ModuleName"="VMware.VimAutomation.Vds";"ModuleVersion"="10.1.0.8344219"}
@{"ModuleName"="VMware.VimAutomation.Vmc";"ModuleVersion"="10.0.0.7893902"}
@{"ModuleName"="VMware.VimAutomation.Nsxt";"ModuleVersion"="10.1.0.8346947"}
#@{"ModuleName"="VMware.VimAutomation.vROps";"ModuleVersion"="10.0.0.7893921"}
@{"ModuleName"="VMware.VimAutomation.Cis.Core";"ModuleVersion"="10.1.0.8377811"}
#@{"ModuleName"="VMware.VimAutomation.HA";"ModuleVersion"="6.5.4.7567193"}
#@{"ModuleName"="VMware.VimAutomation.HorizonView";"ModuleVersion"="7.1.0.7547311"}
#@{"ModuleName"="VMware.VimAutomation.PCloud";"ModuleVersion"="10.0.0.7893924"}
#@{"ModuleName"="VMware.VimAutomation.Cloud";"ModuleVersion"="10.0.0.7893901"}
#@{"ModuleName"="VMware.DeployAutomation";"ModuleVersion"="6.7.0.8250345"}
#@{"ModuleName"="VMware.ImageBuilder";"ModuleVersion"="6.7.0.8250345"}
@{"ModuleName"="VMware.VimAutomation.Storage";"ModuleVersion"="10.1.0.8313015"}
@{"ModuleName"="VMware.VimAutomation.StorageUtility";"ModuleVersion"="1.2.0.0"}
#@{"ModuleName"="VMware.VumAutomation";"ModuleVersion"="6.5.1.7862888"}
)

修正したVMware.PowerCLI.psd1を保存後、再度Import-Moduleを実行する。

PS C:\usr\powershell> Import-Module VMware.PowerCLI
      Welcome to VMware PowerCLI!

Log in to a vCenter Server or ESX host:              Connect-VIServer
To find out what commands are available, type:       Get-VICommand
To show searchable help for all PowerCLI commands:   Get-PowerCLIHelp
Once you've connected, display all virtual machines: Get-VM
If you need more help, visit the PowerCLI community: Get-PowerCLICommunity

       Copyright (C) VMware, Inc. All rights reserved.

Get-Moduleコマンドレットで、読み込まれたVMware.PowerCLIモジュールのバージョンを確認しておく。

PS C:\usr\powershell> Get-Module -Name VMware.PowerCLI | Format-Table -AutoSize

ModuleType Version        Name            ExportedCommands
---------- -------        ----            ----------------
Manifest   10.1.0.8403314 VMware.PowerCLI

使用できるコマンド

Get-VICommandで使用できるコマンドを確認できる。以下に、この対処後に使用できる状態になったコマンドを、モジュールごとに整理する。

VMware.VimAutomation.Cis.Core:

Connect-CisServer,
Disconnect-CisServer,
Get-CisCommand, Get-CisService

VMware.VimAutomation.Core:

Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer, Answer-VMQuestion, Apply-DrsRecommendation, Apply-VMHostProfile,
Connect-VIServer,
Copy-DatastoreItem, Copy-HardDisk, Copy-VMGuestFile,
Disconnect-VIServer,
Dismount-Tools,
Export-VApp, Export-VM, Export-VMHostProfile,
Format-VMHostDiskPartition,
Get-AdvancedSetting, Get-AlarmAction, Get-AlarmActionTrigger, Get-AlarmDefinition, Get-Annotation, Get-CDDrive, Get-Cluster, Get-ContentLibraryItem, Get-CustomAttribute, Get-Datacenter, Get-Datastore, Get-DatastoreCluster, Get-DrsClusterGroup, Get-DrsRecommendation, Get-DrsRule, Get-DrsVMHostRule, Get-ESX, Get-EsxCli, Get-EsxTop, Get-FloppyDrive, Get-Folder, Get-HAPrimaryVMHost, Get-HardDisk, Get-Inventory, Get-IScsiHbaTarget, Get-Log, Get-LogType, Get-NetworkAdapter, Get-NicTeamingPolicy, Get-OSCustomizationNicMapping, Get-OSCustomizationSpec, Get-OvfConfiguration, Get-PassthroughDevice, Get-PowerCLIConfiguration, Get-PowerCLIDocumentation, Get-PowerCLIVersion, Get-ResourcePool, Get-ScsiController, Get-ScsiLun, Get-ScsiLunPath, Get-SecurityPolicy, Get-Snapshot, Get-Stat, Get-StatInterval, Get-StatType, Get-Tag, Get-TagAssignment, Get-TagCategory, Get-Task, Get-Template, Get-UsbDevice, Get-VApp, Get-VC, Get-VIAccount, Get-VICommand, Get-VICredentialStoreItem, Get-VIEvent, Get-View, Get-VIObjectByVIView, Get-VIPermission, Get-VIPrivilege, Get-VIProperty, Get-VIRole, Get-VirtualPortGroup, Get-VirtualSwitch, Get-VIServer, Get-VIToolkitConfiguration, Get-VIToolkitVersion, Get-VM, Get-VMGuest, Get-VMHost, Get-VMHostAccount, Get-VMHostAdvancedConfiguration, Get-VMHostAuthentication, Get-VMHostAvailableTimeZone, Get-VMHostDiagnosticPartition, Get-VMHostDisk, Get-VMHostDiskPartition, Get-VMHostFirewallDefaultPolicy, Get-VMHostFirewallException, Get-VMHostFirmware, Get-VMHostHardware, Get-VMHostHba, Get-VMHostModule, Get-VMHostNetwork, Get-VMHostNetworkAdapter, Get-VMHostNtpServer, Get-VMHostPatch, Get-VMHostPciDevice, Get-VMHostProfile, Get-VMHostProfileRequiredInput, Get-VMHostRoute, Get-VMHostService, Get-VMHostSnmp, Get-VMHostStartPolicy, Get-VMHostStorage, Get-VMHostSysLogServer, Get-VMQuestion, Get-VMResourceConfiguration, Get-VMStartPolicy,
HookGetViewAutoCompleter,
Import-VApp, Import-VMHostProfile,
Install-VMHostPatch,
Invoke-DrsRecommendation, Invoke-VMHostProfile, Invoke-VMScript,
Mount-Tools,
Move-Cluster, Move-Datacenter, Move-Datastore, Move-Folder, Move-HardDisk, Move-Inventory, Move-ResourcePool, Move-Template, Move-VApp, Move-VM, Move-VMHost,
New-AdvancedSetting, New-AlarmAction, New-AlarmActionTrigger, New-CDDrive, New-Cluster, New-CustomAttribute, New-Datacenter, New-Datastore, New-DatastoreCluster, New-DatastoreDrive, New-DrsClusterGroup, New-DrsRule, New-DrsVMHostRule, New-FloppyDrive, New-Folder, New-HardDisk, New-IScsiHbaTarget, New-NetworkAdapter, New-OSCustomizationNicMapping, New-OSCustomizationSpec, New-ResourcePool, New-ScsiController, New-Snapshot, New-StatInterval, New-Tag, New-TagAssignment, New-TagCategory, New-Template, New-VApp, New-VICredentialStoreItem, New-VIInventoryDrive, New-VIPermission, New-VIProperty, New-VIRole, New-VirtualPortGroup, New-VirtualSwitch, New-VM, New-VMHostAccount, New-VMHostNetworkAdapter, New-VMHostProfile, New-VMHostRoute,
Open-VMConsoleWindow,
Remove-AdvancedSetting, Remove-AlarmAction, Remove-AlarmActionTrigger, Remove-CDDrive, Remove-Cluster, Remove-CustomAttribute, Remove-Datacenter, Remove-Datastore, Remove-DatastoreCluster, Remove-DrsClusterGroup, Remove-DrsRule, Remove-DrsVMHostRule, Remove-FloppyDrive, Remove-Folder, Remove-HardDisk, Remove-Inventory, Remove-IScsiHbaTarget, Remove-NetworkAdapter, Remove-OSCustomizationNicMapping, Remove-OSCustomizationSpec, Remove-PassthroughDevice, Remove-ResourcePool, Remove-Snapshot, Remove-StatInterval, Remove-Tag, Remove-TagAssignment, Remove-TagCategory, Remove-Template, Remove-UsbDevice, Remove-VApp, Remove-VICredentialStoreItem, Remove-VIPermission, Remove-VIProperty, Remove-VIRole, Remove-VirtualPortGroup, Remove-VirtualSwitch, Remove-VirtualSwitchPhysicalNetworkAdapter, Remove-VM, Remove-VMHost, Remove-VMHostAccount, Remove-VMHostNetworkAdapter, Remove-VMHostNtpServer, Remove-VMHostProfile, Remove-VMHostRoute,
Restart-VM, Restart-VMGuest, Restart-VMHost, Restart-VMHostService,
Set-AdvancedSetting, Set-AlarmDefinition, Set-Annotation, Set-CDDrive, Set-Cluster, Set-CustomAttribute, Set-Datacenter, Set-Datastore, Set-DatastoreCluster, Set-DrsClusterGroup, Set-DrsRule, Set-DrsVMHostRule, Set-FloppyDrive, Set-Folder, Set-HardDisk, Set-IScsiHbaTarget, Set-NetworkAdapter, Set-NicTeamingPolicy, Set-OSCustomizationNicMapping, Set-OSCustomizationSpec, Set-PowerCLIConfiguration, Set-ResourcePool, Set-ScsiController, Set-ScsiLun, Set-ScsiLunPath, Set-SecurityPolicy, Set-Snapshot, Set-StatInterval, Set-Tag, Set-TagCategory, Set-Template, Set-VApp, Set-VIPermission, Set-VIRole, Set-VirtualPortGroup, Set-VirtualSwitch, Set-VIToolkitConfiguration, Set-VM, Set-VMHost, Set-VMHostAccount, Set-VMHostAdvancedConfiguration, Set-VMHostAuthentication, Set-VMHostDiagnosticPartition, Set-VMHostFirewallDefaultPolicy, Set-VMHostFirewallException, Set-VMHostFirmware, Set-VMHostHba, Set-VMHostModule, Set-VMHostNetwork, Set-VMHostNetworkAdapter, Set-VMHostProfile, Set-VMHostRoute, Set-VMHostService, Set-VMHostSnmp, Set-VMHostStartPolicy, Set-VMHostStorage, Set-VMHostSysLogServer, Set-VMQuestion, Set-VMResourceConfiguration, Set-VMStartPolicy,
Shutdown-VMGuest,
Start-VApp, Start-VM, Start-VMHost, Start-VMHostService,
Stop-Task, Stop-VApp, Stop-VM, Stop-VMGuest, Stop-VMHost, Stop-VMHostService,
Suspend-VM, Suspend-VMGuest, Suspend-VMHost,
TabExpansion2,
Test-VMHostProfileCompliance, Test-VMHostSnmp,
Update-Tools,
Wait-Task, Wait-Tools

VMware.VimAutomation.Nsxt:

Connect-NsxtServer,
Disconnect-NsxtServer,
Get-NsxtService

VMware.VimAutomation.Sdk:

Get-InstallPath, Get-PowerCLICommunity, Get-PowerCLIHelp, Get-PSVersion

VMware.VimAutomation.Storage:

Add-KeyManagementServer,
Copy-VDisk,
Export-SpbmStoragePolicy,
Get-KeyManagementServer, Get-KmipClientCertificate, Get-KmsCluster, Get-NfsUser, Get-SpbmCapability, Get-SpbmCompatibleStorage, Get-SpbmEntityConfiguration, Get-SpbmFaultDomain, Get-SpbmPointInTimeReplica, Get-SpbmReplicationGroup, Get-SpbmReplicationPair, Get-SpbmStoragePolicy, Get-VAIOFilter, Get-VasaProvider, Get-VasaStorageArray, Get-VDisk, Get-VsanClusterConfiguration, Get-VsanDisk, Get-VsanDiskGroup, Get-VsanEvacuationPlan, Get-VsanFaultDomain, Get-VsanIscsiInitiatorGroup, Get-VsanIscsiInitiatorGroupTargetAssociation, Get-VsanIscsiLun, Get-VsanIscsiTarget, Get-VsanResyncingComponent, Get-VsanRuntimeInfo, Get-VsanSpaceUsage, Get-VsanStat, Get-VsanView,
Import-SpbmStoragePolicy,
Move-VDisk,
New-KmipClientCertificate, New-NfsUser, New-SpbmRule, New-SpbmRuleSet, New-SpbmStoragePolicy, New-VAIOFilter, New-VasaProvider, New-VDisk, New-VsanDisk, New-VsanDiskGroup, New-VsanFaultDomain, New-VsanIscsiInitiatorGroup, New-VsanIscsiInitiatorGroupTargetAssociation, New-VsanIscsiLun, New-VsanIscsiTarget,
Remove-KeyManagementServer, Remove-NfsUser, Remove-SpbmStoragePolicy, Remove-VAIOFilter, Remove-VasaProvider, Remove-VDisk, Remove-VsanDisk, Remove-VsanDiskGroup, Remove-VsanFaultDomain, Remove-VsanIscsiInitiatorGroup, Remove-VsanIscsiInitiatorGroupTargetAssociation, Remove-VsanIscsiLun, Remove-VsanIscsiTarget,
Repair-VsanObject,
Set-KeyManagementServer, Set-KmsCluster, Set-NfsUser, Set-SpbmEntityConfiguration, Set-SpbmStoragePolicy, Set-VAIOFilter, Set-VDisk, Set-VsanClusterConfiguration, Set-VsanFaultDomain, Set-VsanIscsiInitiatorGroup, Set-VsanIscsiLun, Set-VsanIscsiTarget,
Start-SpbmReplicationFailover, Start-SpbmReplicationPrepareFailover, Start-SpbmReplicationPromote, Start-SpbmReplicationReverse, Start-SpbmReplicationTestFailover, Start-VsanClusterDiskUpdate, Start-VsanClusterRebalance, Start-VsanEncryptionConfiguration,
Stop-SpbmReplicationTestFailover, Stop-VsanClusterRebalance,
Sync-SpbmReplicationGroup,
Test-VsanClusterHealth, Test-VsanNetworkPerformance, Test-VsanStoragePerformance, Test-VsanVMCreation,
Update-VsanHclDatabase

VMware.VimAutomation.StorageUtility:

Update-VmfsDatastore

VMware.VimAutomation.Vds:

Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost,
Export-VDPortGroup, Export-VDSwitch,
Get-VDBlockedPolicy, Get-VDPort, Get-VDPortgroup, Get-VDPortgroupOverridePolicy, Get-VDSecurityPolicy, Get-VDSwitch, Get-VDSwitchPrivateVlan, Get-VDTrafficShapingPolicy, Get-VDUplinkLacpPolicy, Get-VDUplinkTeamingPolicy,
New-VDPortgroup, New-VDSwitch, New-VDSwitchPrivateVlan,
Remove-VDPortGroup, Remove-VDSwitch, Remove-VDSwitchPhysicalNetworkAdapter, Remove-VDSwitchPrivateVlan, Remove-VDSwitchVMHost,
Set-VDBlockedPolicy, Set-VDPort, Set-VDPortgroup, Set-VDPortgroupOverridePolicy, Set-VDSecurityPolicy, Set-VDSwitch, Set-VDTrafficShapingPolicy, Set-VDUplinkLacpPolicy, Set-VDUplinkTeamingPolicy, Set-VDVlanConfiguration

VMware.VimAutomation.Vmc:

Connect-Vmc, Connect-VmcServer,
Disconnect-Vmc, Disconnect-VmcServer,
Get-VmcService

仮想マシンやvApp、ESXiホストの操作には十分なものがそろってる気がする。

背景

同様のエラーが起きる問題と対処方法が「PowerCLI 10.0.0 Linux Error in VMware.VimAutomation.Srm Module > CloudHat.eu」にこの問題が取り上げられており、10.1でも同様と追記されている。

I will then write about the error I met (“Import-Module : VMware.VimAutomation.Srm module is not currently supported on the Core edition of PowerShell”) and how I solved it. Update 5 May 2018: VMware released a new version 10.1.0, same error is present.

この記事で紹介されている対処方法が、VMware.PowerCLI.psd1を修正する方法だった。この対処方法で活かしたままになっているモジュールは、New Release: VMware PowerCLI 10.0.0 - VMware PowerCLI Blog - VMware Blogsの下記の箇所でサポート対象に挙げられているモジュールとVMware.Vimだったので、サポート対象外のモジュールを外すという考え方とその対象は正しいと思われた。

The PowerCLI 10.0.0 release starts with support for the following modules, and the rest of the modules will be added over time:

  • VMware.VimAutomation.Cis.Core
  • VMware.VimAutomation.Common
  • VMware.VimAutomation.Core
  • VMware.VimAutomation.Nsxt
  • VMware.VimAutomation.Vds
  • VMware.VimAutomation.Vmc
  • VMware.VimAutomation.Sdk
  • VMware.VimAutomation.Storage
  • VMware.VimAutomation.StorageUtility

CloudHat.euの記事はUbuntu上のPowerCLI 10.0版を対象にしており、ここで試しているのはWindows上のPowerCLI 10.1版なので、差異があるかもしれないとは考えた。そこで、Import-Module実行時のエラーメッセージを確認し、そこで表示されたモジュールをコメント化して、再度Import-Moduleを実行するということを繰り返した。結果的には、有効なままにしておけたモジュールは、10.1版でもVMware Blogsの記載と一致した。

参考


本ページ内容は筆者が参照の便のためにある時点でまとめた個人的なメモです。内容を保証するものではなく、また筆者の所属組織等とは一切かかわりがありません。