Learn about Robin's blog post, the original address below is his summary automation management is becoming more and more common,hyper-v virtual machines also can. Premise: system server 2008 above,powershell 3.0, import Hyper-V Library 1. Virtual Machine Automatic backup set-executionpolicy unrestricted #信任脚本Import-module d:\hyperv\hyperv\hyperv.psd1 # Every execution to the import library $BackupDriver = "E:" #备份驱动盘符 $BackupFolder = $ (get-date -uformat "%y%m%d") #备份文件夹名, Format is date new-item -path $BackupDriver -name $BackupFolder -type directory $VM = "XPx32", "win7x64" #分别备份 hyper-v the name of the virtual machine foreach ($i in $VM) { shutdown-vm $i  -FORCE  START-SLEEP 30  EXPORT-VM $i $BackupDriver \ $BackupFolder \ $i "_" $ (get-date -uformat "%y%m%d%h%m") -copystate –wait Start-Sleep 60 start-vm $i start-sleep 60 } 2. virtual machine hard disk compression The following is a compressed command of the virtual machine hard disk compact-vhd and  COMPRESS-VHD can be implemented, the same functionality. With regard to the use of the actual production, I recommend to perform in idle time. I usually continue after the patch update so after compressing the backup VM, can also automate execution, the ultimate goal is to optimize the Hyper-V virtual machine Compress -VHD -VHDPaths ' e:\ Hyperv_runing\vhd\xpx32.vhd ' #compress vhd compressed disk The path to the virtual machine disk: ' E:\HyperV_Runing\VHD\XPx32.vhd ' Get-wmiobject -namespace root\virtualization msvm_storagejob | ft jobstatus, description, percentcomplete -auto #compress status View background compression
PowerShell learning------hpyer-v Virtual machine optimization (backup, compressed disk)