Quantcast
Viewing all articles
Browse latest Browse all 816

PowerCLIで対象の仮想マシンを選択しつvMotionを実行

VMware vSphere環境で、PowerCLIを使って、仮想マシンのvMotionを行うスクリプトを作成した。

ブラウザを起動し、vSphere Web Clientにログインして、vMotionを実行するまでにかかる時間と
PowerShellを起動して、コマンドを実行する時間を比べると
コマンドを実行したほうがずっと早い、ということで作成した。

というか、vSphere Web Clientは重すぎ!

# 普通のPowerShell/PowerShell ISEからvSphere PowerCLIのコマンドを使うために必要な設定
Add-PSSnapin VMware.VimAutomation.Core
# vCenterサーバに接続
$VC=Connect-VIServer -User "administrator@vsphere.local" -Password "パスワード" "vCenterサーバ"  -WarningAction 0
# 仮想マシンの選択
$VM=Get-VM | Out-GridView -Title "Please select VM" -PassThru
# 選択した仮想マシンが所属しているクラスタのESXiホストリストから選択
$ESX=Get-VMHost -Location  ($VM.ResourcePool).Name | Out-GridView -Title "Please select ESXi host" -PassThru
# 選択したものを表示
Write-Host "VirtualMachine:" $VM.Name
Write-Host "Move from:" $VM.VMHost " to:" $ESX.Name
# vMotionを実行
Move-VM -VM $VM -Destination $ESX

なお、「$VM=Get-VM | Out-GridView -Title “Please select VM” -PassThru」を
「$VM=Get-VM | Select Name,VMHost | Out-GridView -Title “Please select VM” -PassThru」
という風に替えると、選択ウィンドウに表示する内容を変えることができる。

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 816

Trending Articles