Virtual Kim

@Kim_Bottu … Virtually Gung Ho

Put ESXi host in Maintenance, move specific VM to specific ESXi host, create backup of Host configuration

#1. Script puts $Host in Maintenance mode.
#2. Script moves the specific VM’s to a specific host called $Destination
#3. Script will create a backup of the ESXi configuration of host $Host to C:\HostBackups
# If the script seems to hang, tap the space bar, the script will continue.
# Change the name of $VMHost, $Destination and the reference to the specific VM’s (VMSpecial*) in the script.

$VMHost = host1.esxi.local
$Destination = host2.esxi.local

#1. Script puts Host in Maintenance mode.

Write-host Put Host in Maintenance mode and allow the execution of code while the host is still not in maintenance mode.

$task = Set-VMHost -VMHost $VMHost -State “Maintenance” -RunAsync


#2. Move the specific VM’s to specific $Destination

Get-VM -Name VMSpecial* | Move-VM -Destination $Destination

write-host SPecific VM’s have been moved


#3. Back up ESXi configuration to C:\HostBackups

Write-Host “Backing up ESXi config to C:\HostBackups”


Get-VMHostFirmware -VMHost $VMHost -BackupConfiguration -DestinationPath C:\HostBackups

Write-Host “Backup is completed!”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


This entry was posted on March 16, 2015 by in Backup, ESXI, PowerCLI, Script and tagged , , , .
Follow Virtual Kim on

Blog Stats

  • 27,573 hits
%d bloggers like this: