(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【WindowsServer】VMwarePowerCLIのコマンドをオフラインでインストールする

スポンサーリンク

はじめに

PowerCLIはVMware製品であるESXiやvCenterに対してコマンドから操作するためのツールです。
本記事ではインターネットに接続していないOfflineの環境にてPowerCLIのコマンド(Connect-VIServer)をWindowsServerにInstallする流れを記載しました。

環境情報

  • Microsoft Windows Server 2016 Standard
  • VMware.PowerCLI 12.0

モジュールのインストール

VMware社が提供するVMware-PowerCLIのモジュール群がZip形式で配布されているので取得します。
今回は「VMware-PowerCLI-12.0.0-15947286.zip」を利用します。

ZIpを展開すると以下のようなディレクトリ構成となっています。

$ ls
 VMware.VimAutomation.License
 VMware.CloudServices               VMware.VimAutomation.Nsxt
 VMware.DeployAutomation            VMware.VimAutomation.Sdk
 VMware.ImageBuilder                VMware.VimAutomation.Security
 VMware.PowerCLI                    VMware.VimAutomation.Srm
 VMware.Vim                         VMware.VimAutomation.Storage
 VMware.VimAutomation.Cis.Core      VMware.VimAutomation.StorageUtility
 VMware.VimAutomation.Cloud         VMware.VimAutomation.Vds
 VMware.VimAutomation.Common        VMware.VimAutomation.Vmc
 VMware.VimAutomation.Core          VMware.VimAutomation.vROps
 VMware.VimAutomation.Hcx           VMware.VimAutomation.WorkloadManagement
 VMware.VimAutomation.HorizonView   VMware.VumAutomation

WindowServerに配置

管理者権限でPowrshellを開いた状態で以下コマンドを押下すると結果は何も返ってきません。

PS C:\Users\Administrator> Get-Module -Name VMware.PowerCLI -ListAvailable

一方でWIndowsServerのC:\Program Files\WindowsPowerShell\Modulesに同フォルダ群を配置すると

PS C:\Users\Administrator> Get-Module -Name VMware.PowerCLI -ListAvailable


    ディレクトリ: C:\Program Files\WindowsPowerShell\Modules


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

と結果が返ってきます。

この状態にて同結果を引数としてImport-Moduleに渡すと

PS C:\Users\Administrator> Get-Module -Name VMware.PowerCLI -ListAvailable | Import-Module

以下のような警告文の元でインストールが進みました。

警告: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a better product. You can join using the following command:

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

To disable this warning and set your preference use the following command and restart PowerShell:
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.

上記警告文の後に以下メッセージが表示されます。

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.

警告は出たものの問題なくコマンドが通るようになりました。

PS C:\Users\Administrator> Connect-VIServer

コマンド パイプライン位置 1 のコマンドレット Connect-VIServer
次のパラメーターに値を指定してください:
Server[0]:

終わりに

同コマンドを利用するためにインストールする場合はVMwarevSpherePowerCLIといったツールは不要となります。
逆に、事前に同ツールのインストールが中途半端に入っている場合は以下のエラーとなりました。

 Get-Module -Name VMware.PowerCLI -ListAvailable | Import-Module
Import-Module : "2" 個の引数を指定して "OnImportModule" を呼び出し中に例外が発生しました: "'VMware.VimAutomation.Storage.Interop.V1.Service.StorageServiceFactory' のタイプ初期化子が例外をスローしました。"
発生場所 行:1 文字:51
+ Get-Module -Name VMware.PowerCLI -ListAvailable | Import-Module
+                                                   ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], MethodInvocationException
    + FullyQualifiedErrorId : TypeInitializationException,Microsoft.PowerShell.Commands.ImportModuleCommand

以上、ご参考になれば幸いです。