vSphere PowerCLIの一部コマンドがPowerShell ISEで動作しない


2016/12/15追記

Add-Snappinは、古いPowerShellの場合だけだったようなので、新しいバージョンの場合にも対応したものを下記に記載しています。

vSphere PowerCLIの一部コマンドがPowerShell ISEで動作しない 2016/12/15版


vSphere PowerCLIで変な動作に遭遇した。
vSphere PowerCLIの一部コマンドがPowerShell ISE上だと動作しない、という問題である。
元々、PowerShell ISEの標準設定ではvSphere PowerCLIのコマンドは動かない。
「Add-PSSnapin VMware.VimAutomation.Core」を追加し、モジュールを読み込ませる必要があるのだが、それを行っても動かないものがいくつかあることが分かった。

まずは状況の確認から・・・

現在のvSphere Power CLIのバージョンを確認
Determining the build number for vSphere PowerCLI or VI Toolkit for Windows」より「Get-VIToolkitVersion」を実行。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VIToolkitVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 6.0 Release 1 build 2548067
---------------
Component Versions
---------------
   VMWare AutoDeploy PowerCLI Component 6.0 build 2358282
   VMWare ImageBuilder PowerCLI Component 6.0 build 2358282
   VMware License PowerCLI Component 6.0 build 2315846
   VMware vSphere PowerCLI Component 6.0 build 2548068
   VMware Cloud Infrastructure Suite PowerCLI Component 6.0 build 2548068
   VMware HA PowerCLI Component 6.0 build 2510422
   VMware PowerCLI Component for Storage Management 6.0 build 2522368
   VMware VDS PowerCLI Component 6.0 build 2548068



PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

(ちなみに、この記事を書いてる時点では、これより新しいバージョンが出ている)

vCenterサーバに接続

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Connect-VIServer -Server vCenterServer -User root -Password vmware

Name                           Port  User
----                           ----  ----
vCenterServer                  443   root


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

そして、「Get-VdsCommand」を実行してvSphre PowerCLIが提供するvDS関連コマンド一覧を取得。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VdsCommand

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Cmdlet          Add-VDSwitchPhysicalNetworkAdapter                 VMware.Vi...
Cmdlet          Add-VDSwitchVMHost                                 VMware.Vi...
Cmdlet          Export-VDPortGroup                                 VMware.Vi...
Cmdlet          Export-VDSwitch                                    VMware.Vi...
Cmdlet          Get-VDBlockedPolicy                                VMware.Vi...
Cmdlet          Get-VDPort                                         VMware.Vi...
Cmdlet          Get-VDPortgroup                                    VMware.Vi...
Cmdlet          Get-VDPortgroupOverridePolicy                      VMware.Vi...
Cmdlet          Get-VDSecurityPolicy                               VMware.Vi...
Cmdlet          Get-VDSwitch                                       VMware.Vi...
Cmdlet          Get-VDSwitchPrivateVlan                            VMware.Vi...
Cmdlet          Get-VDTrafficShapingPolicy                         VMware.Vi...
Cmdlet          Get-VDUplinkLacpPolicy                             VMware.Vi...
Cmdlet          Get-VDUplinkTeamingPolicy                          VMware.Vi...
Cmdlet          New-VDPortgroup                                    VMware.Vi...
Cmdlet          New-VDSwitch                                       VMware.Vi...
Cmdlet          New-VDSwitchPrivateVlan                            VMware.Vi...
Cmdlet          Remove-VDPortGroup                                 VMware.Vi...
Cmdlet          Remove-VDSwitch                                    VMware.Vi...
Cmdlet          Remove-VDSwitchPhysicalNetworkAdapter              VMware.Vi...
Cmdlet          Remove-VDSwitchPrivateVlan                         VMware.Vi...
Cmdlet          Remove-VDSwitchVMHost                              VMware.Vi...
Cmdlet          Set-VDBlockedPolicy                                VMware.Vi...
Cmdlet          Set-VDPort                                         VMware.Vi...
Cmdlet          Set-VDPortgroup                                    VMware.Vi...
Cmdlet          Set-VDPortgroupOverridePolicy                      VMware.Vi...
Cmdlet          Set-VDSecurityPolicy                               VMware.Vi...
Cmdlet          Set-VDSwitch                                       VMware.Vi...
Cmdlet          Set-VDTrafficShapingPolicy                         VMware.Vi...
Cmdlet          Set-VDUplinkLacpPolicy                             VMware.Vi...
Cmdlet          Set-VDUplinkTeamingPolicy                          VMware.Vi...
Cmdlet          Set-VDVlanConfiguration                            VMware.Vi...


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> 

ここまでは良い。

PowerShell ISEでの動作が問題。
PowerShell ISE上部の編集画面に下記を入力。

Add-PSSnapin VMware.VimAutomation.Core
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand

最初の1行はvSphere PowerCLIのコマンドを実行させるため設定。
これを実行すると・・・

PS C:\Users\osakanataro> Add-PSSnapin VMware.VimAutomation.Core
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand

Get-VIToolkitVersion : 用語 'Get-VIToolkitVersion' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、
再試行してください。
発生場所 行:2 文字:1
+ Get-VIToolkitVersion
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-VIToolkitVersion:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 

Name                           Port  User                          
----                           ----  ----                          
vCenterServer                  443   root                          
Get-VdsCommand : 用語 'Get-VdsCommand' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。
発生場所 行:4 文字:1
+ Get-VdsCommand
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-VdsCommand:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 



PS C:\Users\osakanataro> 

エラーになる・・・
なぜなのか・・・

まずはPowerShell ISE内で「Get-Module」を実行し、現在使用できるコマンドを確認

PS C:\Users\osakanataro> Get-Module

ModuleType Version    Name                                ExportedCommands                                                                            
---------- -------    ----                                ----------------                                                                            
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                         
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                          
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}   
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}                                   
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}             



PS C:\Users\osakanataro> 

比較のためvSphere PowerCLIの方でも「Get-Module」を実行してみる

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        Initialize-VMware_VimAutomation_Cis
Script     0.0        Initialize-VMware_VimAutomation_Vds
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-T...
Binary     6.0.0.0    VMware.VimAutomation.Cis.Core       {Connect-CisServer...
Manifest   6.0.0.0    VMware.VimAutomation.Core           {Add-PassthroughDe...
Binary     6.0.0.0    VMware.VimAutomation.HA             Get-DrmInfo
Manifest   6.0.0.0    VMware.VimAutomation.Sdk
Binary     6.0.0.0    VMware.VimAutomation.Storage        {Export-SpbmStorag...
Binary     6.0.0.0    VMware.VimAutomation.Vds            {Add-VDSwitchPhysi...


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

全然違う
「VMware.VimAutomation.Vds」を追加すると実行できそうな雰囲気・・・

しかし、「Add-PSSnapin VMware.VimAutomation.Vds」は下記のエラーとなる。

Add-PSSnapin : Windows PowerShell スナップイン 'VMware.VimAutomation.Vds' がこのコンピューターにインストールされていません。
発生場所 行:2 文字:1
+ Add-PSSnapin VMware.VimAutomation.Vds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (VMware.VimAutomation.Vds:String) [Add-PSSnapin]、PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

ではどうするか?

「Get-Command -Module モジュール名」で指定したモジュールでどんなコマンドが実行できるかを表示すると実行でいるようになるらしい。

そんな馬鹿な、と思いつつ、$DUMMY環境変数に放り込むように変更。

Add-PSSnapin VMware.VimAutomation.Core
$DUMMY=Get-Command -Module VMware.VimAutomation.Vds
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand

そして実行

PS C:\Users\osakanataro> Add-PSSnapin VMware.VimAutomation.Core
$DUMMY=Get-Command -Module VMware.VimAutomation.Vds
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand


PowerCLI Version
----------------
   VMware vSphere PowerCLI 6.0 Release 1 build 2548067
---------------
Component Versions
---------------
   VMWare AutoDeploy PowerCLI Component 6.0 build 2358282
   VMWare ImageBuilder PowerCLI Component 6.0 build 2358282
   VMware License PowerCLI Component 6.0 build 2315846
   VMware vSphere PowerCLI Component 6.0 build 2548068
   VMware VDS PowerCLI Component 6.0 build 2548068


IsConnected   : True
Id            : /VIServer=root@vCenterServer:443/
ServiceUri    : https://vCenterServer/sdk
SessionSecret : cb8924f9fb4b2cb6cb75a357d8127e2154376d17
Name          : vCenterServer
Port          : 443
SessionId     : cb8924f9fb4b2cb6cb75a357d8127e2154376d17
User          : root
Uid           : /VIServer=root@vCenterServer:443/
Version       : 6.0
Build         : 2776510
ProductLine   : vpx
InstanceUuid  : 1a31cfc8-0931-4752-9573-461f044cc2d4
RefCount      : 6
ExtensionData : VMware.Vim.ServiceInstance
Client        : VMware.VimAutomation.ViCore.Impl.V1.VimClient


Verb                : Add
Noun                : VDSwitchPhysicalNetworkAdapter
HelpFile            : VMware.VimAutomation.Vds.Commands.dll-Help.xml
PSSnapIn            : 
ImplementingType    : VMware.VimAutomation.Vds.Commands.Cmdlets.AddVDSwitchPhysicalNetworkAdapter
Definition          : 
                      Add-VDSwitchPhysicalNetworkAdapter [-VMHostPhysicalNic] <PhysicalNic&#91;&#93;> [-DistributedSwitch] <DistributedSwitch> [-VirtualNicPor
                      tgroup <VDPortgroup&#91;&#93;>] [-VMHostVirtualNic <HostVirtualNic&#91;&#93;>] [-Server <VIServer&#91;&#93;>] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
DefaultParameterSet : 
OutputType          : {System.Void}
Options             : ReadOnly
Name                : Add-VDSwitchPhysicalNetworkAdapter
CommandType         : Cmdlet
Visibility          : Public
ModuleName          : VMware.VimAutomation.Vds
Module              : VMware.VimAutomation.Vds
RemotingCapability  : PowerShell
Parameters          : {[VMHostPhysicalNic, System.Management.Automation.ParameterMetadata], [DistributedSwitch, System.Management.Automation.Parameter
                      Metadata], [VirtualNicPortgroup, System.Management.Automation.ParameterMetadata], [VMHostVirtualNic, System.Management.Automatio
                      n.ParameterMetadata]...}
ParameterSets       : {[-VMHostPhysicalNic] <PhysicalNic&#91;&#93;> [-DistributedSwitch] <DistributedSwitch> [-VirtualNicPortgroup <VDPortgroup&#91;&#93;>] [-VMHostVi
                      rtualNic <HostVirtualNic&#91;&#93;>] [-Server <VIServer&#91;&#93;>] [-WhatIf] [-Confirm] [<CommonParameters>]}
HelpUri             : http://www.vmware.com/support/developer/PowerCLI/PowerCLI60R1/html/Add-VDSwitchPhysicalNetworkAdapter.html
DLL                 : C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VimAutomation.Vds\VMware.VimAutomation.Vds.Commands
                      .dll

<略>

Verb                : Set
Noun                : VDVlanConfiguration
HelpFile            : VMware.VimAutomation.Vds.Commands.dll-Help.xml
PSSnapIn            : 
ImplementingType    : VMware.VimAutomation.Vds.Commands.Cmdlets.Policies.SetVDVlanConfiguration
Definition          : 
                      Set-VDVlanConfiguration -VDPortgroup <VDPortgroup&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateV
                      lanId <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
                      Set-VDVlanConfiguration -VDSwitch <VDSwitch&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId 
                      <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
                      Set-VDVlanConfiguration -VDPort <VDPort&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId <int
                      >] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
DefaultParameterSet : 
OutputType          : {VMware.VimAutomation.Vds.Types.V1.VlanConfiguration}
Options             : ReadOnly
Name                : Set-VDVlanConfiguration
CommandType         : Cmdlet
Visibility          : Public
ModuleName          : VMware.VimAutomation.Vds
Module              : VMware.VimAutomation.Vds
RemotingCapability  : PowerShell
Parameters          : {[VDPortgroup, System.Management.Automation.ParameterMetadata], [VDSwitch, System.Management.Automation.ParameterMetadata], [VDP
                      ort, System.Management.Automation.ParameterMetadata], [DisableVlan, System.Management.Automation.ParameterMetadata]...}
ParameterSets       : {-VDPortgroup <VDPortgroup&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId <int>] [-WhatIf] 
                      [-Confirm] [<CommonParameters>], -VDSwitch <VDSwitch&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-Priva
                      teVlanId <int>] [-WhatIf] [-Confirm] [<CommonParameters>], -VDPort <VDPort&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <V
                      lanRangeList>] [-PrivateVlanId <int>] [-WhatIf] [-Confirm] [<CommonParameters>]}
HelpUri             : http://www.vmware.com/support/developer/PowerCLI/PowerCLI60R1/html/Set-VDVlanConfiguration.html
DLL                 : C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VimAutomation.Vds\VMware.VimAutomation.Vds.Commands
                      .dll




PS C:\Users\osakanataro> 

ほんとに実行できたーーー
じゃぁ、この段階での「Get-Module」はどうなってるか確認してみると、ちゃんとVMware.VimAutomation.Vdsが読み込まれてる・・・
謎な動作をしてますね・・・

PS C:\Users\osakanataro> Get-Module

ModuleType Version    Name                                ExportedCommands                                                                            
---------- -------    ----                                ----------------                                                                            
Script     0.0        Initialize-VMware_VimAutomation_Vds                                                                                             
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                         
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                          
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}   
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}                                   
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}             
Manifest   6.0.0.0    VMware.VimAutomation.Core                                                                                                       
Manifest   6.0.0.0    VMware.VimAutomation.Sdk                                                                                                        
Binary     6.0.0.0    VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwi...



PS C:\Users\osakanataro> 

Win7 32bitをWin10 64bitにしたメモ


中古でWindows 7 32bitのパソコンを入手した。

まぁ、状態がよくわからんし、メモリを4GB以上にしたいから、64bitに入れ替えたいけど、Win7 64bitメディアもってないしなー、ということで、Windows10 64bitにしてみることにした。
なお、Win7 32bit上のデータは全て捨てた。

手順
1. Windows 7 32bitを起動
2. Windows 7のライセンス認証が通ってることを確認
3. 「Windows 10 のダウンロード」で32bitバージョンのツールをダウンロード
4. まずは「他のPC用にインストールメディアを作る」を選んで「アーキテクチャ 64ビット」用のメディアを作成
5. もう1回ツールを起動し「このPCを今すぐアップデートする」を実施
6. 2時間弱待つ
7. Windows10 32bitが起動してくる
8. Windows10のライセンス認証が通っていることを確認
9. シャットダウン
10. 4で作成したメディアで起動
11. Windows10 64のインストールを行う
12. 途中2回あるライセンス入力は「スキップ」を選択 ← <超重要>
13. 1時間強待つ
14. Windows10 64bitが起動してくる
15. Windows10のライセンス認証が通っていることを確認

PowerShellを使ってVMwareのテンプレートからデプロイで「既存のカスタマイズ仕様を使用してカスタマイズする」を行う方法


VMware vSphere環境にて、一度、GUI操作でテンプレートのデプロイを行い、その結果をカスタマイズ仕様として保存している、という状態で、VMware Power CLIを使用して、GUIの「既存のカスタマイズ仕様を使用してカスタマイズする」相当の操作を行う場合、どのようにするかを説明する。

手順のポイント

・カスタマイズ仕様は「OSCustomizationSpec」と「OSCustomizationNicMapping」の2つから成り立っている

・既存のカスタマイズ仕様をコピーした一時的なカスタマイズ仕様を作成し、それを編集して使用する

・仮想マシンの電源を1度入れないとカスタマイズされない(カスタマイズ後、再起動される)

・使うcmdletは以下
  カスタマイズ仕様関連
    Get-OSCustomizationSpec, New-OSCustomizationSpec
    Get-OSCustomizationNicMapping, Set-OSCustomizationNicMapping
  テンプレートデプロイ関連
    Get-VMHost
    New-VM
  仮想マシンのハードウェア構成変更
    Get-VM, Set-VM

手順解説

その1 vCenterサーバに接続

vSphere PowerCLIによる操作を行う際、まずは「Connect-VIServer」により、操作対象のvCenterサーバに接続します。

下記はvCenter vApp(VCSA)の初期設定である「root」「vmware」で接続する場合の例です。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Connect-VIServer -Server IPアドレス -User root -Password vmware

Name                           Port  User
----                           ----  ----
IPアドレス                     443   root


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その2 既存カスタマイズ仕様をコピーしたカスタマイズ仕様を作成

既存のカスタマイズ仕様を一時的に変更してデプロイする、ということができないため、コピーしたカスタマイズ仕様を変更する、という手順を取る。

ただ、コピーの際に「-Type NonPersistent」というオプションを指定すると、このセッション中のみ使用できる一時的なカスタマイズ仕様として作成することができるため、デプロイ後の削除まで考える必要はない。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-OSCustomizationSpec cent6-dep | New-OSCustomizationSpec -Name cent6-temp -Type NonPersistent

Name                                         Description Type          OSType
----                                         ----------- ----          ------
cent6-temp                                               NonPersistent Linux


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その3 IPアドレスなど設定

IPアドレスやデフォルトゲートウェイなどネットワークに関する設定は「Get-OSCustomizationNicMapping」にて行う。

NICを増やす場合もここで行う。(ホスト名についてはここでは無い)

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-OSCustomizationNicMapping -Spec cent6-temp | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 172.17.44.55 -SubnetMask 255.255.0.0 -DefaultGateway 172.17.44.39

Position IPMode           IPAddress       DefaultGateway
-------- ------           ---------       --------------
       1 UseStaticIP      172.17.44.55    172.17.44.39


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その4 仮想マシンホスト名の命名規則指定

仮想マシンにつけるホスト名をどのようなルールで行うかというのを指定する。

「-NamingScheme vm」は、仮想マシンの登録名とホスト名を同じとする、というものになる。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-OSCustomizationSpec cent6-temp | Set-OSCustomizationSpec -NamingScheme vm

Name                                         Description Type          OSType
----                                         ----------- ----          ------
cent6-temp                                               NonPersistent Linux


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その5 仮想マシンのデプロイ

今回は「nimblestorage」という名前のDataStoreを指定して、仮想マシンのデプロイを実施するという形で実行している。

先の項目で、仮想マシンの登録名とホスト名を同じとしているので「-Name cent6-ip55」で指定した「cent6-ip55」がホスト名となる。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> New-VM -Name cent6-ip55  -VMHost vmserver21.vmlab.local -Template cent6-deploy -OSCustomizationSpec cent6-temp -Datastore nimblestorage

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOff 1        2.000


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

なお、デプロイ中に強制終了を行うと、それ以後、動作がおかしくなることがあるようだ。

今回遭遇した事例としては、下記の様なエラーがでるが、デプロイ自体は実施されていた。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> New-VM -Name cent6-ip55 -VMHost vmserver21.vmlab.local -Template cent6-deploy -OSCustomizationSpec cent6-temp -Datastore nimblestorage
New-VM : 2015/07/16 18:03:02    New-VM        オブジェクトの現在の状態に問題が
あるため、操作は有効ではありません。
発生場所 行:1 文字:1
+ New-VM -Name cent6-ip55 -VMHost vmserver21.vmlab.local -Template cent6-depl
oy  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.NewVM

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その6 CPU/メモリの変更

作成した仮想マシンのCPUとメモリの割り当てを「Set-VM」で変更します。

なお、このSet-VMには「-Name」というオプションがありますが、仮想マシンを指定する際は「-VM 仮想マシン名」という風に指定します。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Set-VM -VM cent6-ip55 -NumCpu 2 -MemoryMB 4

Confirmation
Proceed to configure the following parameters of the virtual machine with name
'cent6-ip55'?
New MemoryMB: 4MB
New NumCpu: 2
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)
[?] ヘルプ(既定値は "Y"): y

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOff 2        0.004


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

上記の出力結果をよく見てみるとわかるのですが、実はメモリ容量はMB単位での指定となっています。このため、現状はなんと4MBしか割り当てられていません。これではMS-DOSぐらいしか起動できません。

「4G」と指定したいところですが、サポートされていないため、「4096」という形で指定します。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Set-VM -VM cent6-ip55 -NumCpu 2 -MemoryMB 4096

Confirmation
Proceed to configure the following parameters of the virtual machine with name
'cent6-ip55'?
New MemoryMB: 4096MB
New NumCpu: 2
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)
[?] ヘルプ(既定値は "Y"): y

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOff 2        4.000


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その7 仮想マシンの電源ON

デプロイ時の初期設定は仮想マシンの初回起動時に行われるため、まずはPowerShellから電源オンを行うため「Start-VM」を実行します。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Start-VM -VM cent6-ip55

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOn  2        4.000


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

電源投入後、初回起動時にホスト名/IPアドレスの設定スクリプトが実行されます。また、完了後、自動的に再起動も行われます。

その8 デプロイ完了

再起動が終わったらデプロイが完了です。

Windows7でGet-AzureVM | Out-GridViewが動作しない



Azure環境をCLIで操作するためのMicrosoft Azure PowerShellですが、最近のバージョンでは、Windows 7 SP1のPowerShell 3.0では正常に動作しないコマンドがあるようです。

まず、現在のPower Shellのバージョンは「$PSversiontable」で確認できます。

PS C:\> $PSversiontable

Name                           Value
----                           -----
PSVersion                      3.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34209
BuildVersion                   6.2.9200.16398
PSCompatibleVersions           {1.0, 2.0, 3.0}
PSRemotingProtocolVersion      2.2


PS C:\>

上記の「PSVersion」がPower Shellのバージョンになります。

次に、Azure Power Shellのバージョンは「(Get-Module Azure).version」で確認できます。

PS C:\> (Get-Module azure).version

Major  Minor  Build  Revision
-----  -----  -----  --------
0      9      2      -1

PS C:\>

上記の場合「0.9.2」です

この場合、「$vm = Get-AzureVM | Out-GridView -Title “Select a VM …” -PassThru」を実行すると、

PS C:\> $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru
Get-AzureVM : パイプラインが停止されています。
発生場所 行:1 文字:7
+ $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru
+       ~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureVM]、PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand

Out-GridView : インデックスが範囲を超えています。負でない値で、コレクションのサイズよりも小さくなければなりません。
パラメーター名:index
発生場所 行:1 文字:21
+ $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Out-GridView], ArgumentOutOfRangeException
    + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.PowerShell.Commands.OutGridViewCommand

PS C:\>

Out-GridViewが「ArgumentOutOfRangeException」ということで実行できません。
(「(Get-AzureVM).Name | Out-GridView -PassThue」は実行できるんだけど、得られる出力では次の処理ができない)

この現象はMicrosoftがgithubに開設しているアカウントに報告されている。
Possible breaking change Get-AzureVM breaks pipeline with Out-Gridview (#3047) #13

これによると、どうやら、Power Shell 4.0が必要らしい。

Windows Management Framework 4.0」の一部としてPower Shell 4.0が配布されているので、こちらからダウンロードしてインストールする。
リンク先でダウンロードすると、いくつかのファイルがダウンロードできるが、Windows7の64bit環境で必要なものは「Windows6.1-KB2819745-x64-MultiPkg.msu」だけである。Windows7 32bitの場合は Windows6.1-KB2819745-x86.msu」

インストール&再起動後にPower Shellの状況を確認すると、以下のようになる。

PS C:\>  $PSversiontable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34209
BuildVersion                   6.3.9600.16406
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2


PS C:\> (Get-Module azure).version

Major  Minor  Build  Revision
-----  -----  -----  --------
0      9      2      -1


PS C:\>

で・・改めて「$vm = Get-AzureVM | Out-GridView -Title “Select a VM …” -PassThru」を実行!

PS C:\> $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru
Get-AzureVM : パイプラインが停止されています。発生場所 行:1 文字:7
+ $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru
+       ~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureVM]、PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand

Out-GridView : インデックスが範囲を超えています。負でない値で、コレクションのサイズよりも小さくなければなりません。
パラメーター名:index発生場所 行:1 文字:21
+ $vm = Get-AzureVM | Out-GridView -Title "Select a VM ..." -PassThru
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Out-GridView], ArgumentOutOfRangeException
    + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.PowerShell.Commands.OutGridViewCommand

PS C:\>

・・・あの・・・?

というわけで、当初もくろんでいたPower Shellを4.0にすることで対処できる、というわけではなく
アップデートしても、なんともならない、という救いようのない状態に・・・・

う~ん・・・


2015/07/21追記

githubのissue」にコメントが付いた

It’s a bug in PS 3.0 and 4.0 in that it fails to load the object and/or type info, if TableControl is not correctly configured.

This will be patched on our end for 3.0/4.0 in the incoming release. Stay tune. Thanks.

PowerShell 3.0と4.0におけるバグで、今度のリリースで修正される、とのこと。

Azure上の仮想ディスクを拡張する



このページの内容は「Azure上の仮想マシンのディスク拡張手法 2016年1月版」に置き換わりました。


Azure上にある仮想マシンで使用しているディスクの残り容量が減ってきた。
拡張するための手順を確認すると、一度VHDをダウンロードし、ローカルで拡張操作をした後に、再アップロードする、といったものが出てくる。

そんなバカな、と調べてみたところ、現在はそんなことをしなくてもいようだ。

Resizing Data Disks in the Cloud on Microsoft Azure with Windows PowerShell

Azure Power Shellモジュールのversion 0.8.15.1以降であれば、「Update-AzureDisk」のオプションとして「-ResizedSizeInGB」が追加されており、それを使用することで拡張することができる、とのこと。

ただ、2015/06/01現在、Azureのドキュメントの「Update-AzureDisk」は、version 0.8.10準拠ということで、このオプションが載っておらず、半ば隠しオプションとなってしまっている。

いや・・・ちゃんとしてくれよ・・・

しかも、Windows7で試したところ、Azure PowerShellモジュールを2015/06/01時点での最新ver 0.9.2にしても、このページ記載のコマンドが実行できないという事態も発覚。

「$vm = Get-AzureVM | Out-Gridview -PassThru」が失敗するという・・・

下記の問題と同様のようだ。
Possible breaking change Get-AzureVM breaks pipeline with Out-Gridview (#3047) #13

どうやらPower Shell 3.0では、動かず、Power Shell 4.0にする必要があるらしい。

そして、Power Shellは、Windows Management Framework 4.0に含まれるため
Windows Management Framework 4.0」を導入する必要がある、とのこと。

めんどくさいなぁ・・・・