最近某個客戶為了能夠在更新Windows 7母版之後,shell
在不動到Studio的狀況下,每個月能夠自動更新,ide
所以為了這個需求寫了一個Powershell,並套進在Windows 2012的工做排成之中。spa
先說明基本環境orm
Hypervisor:XenServer 6.5ci
OS:Windows 2012 R2get
虛擬桌面版本:Xendesktop7.6.3it
$Today=Get-Date -UFormat %Y%m%d_%H%M%S ##設定Snapshot日期io
New-HypVMSnapshot -AdminAddress "ddc.citrix.com:80" -LiteralPath "XDHyp:\HostingUnits\dd\Windows 7 test.vm" -SnapshotName "Citrix_$Today" ##執行Snapshot的VMast
$ProvSchemeName = "TESTSCRIPTS" ##須要針對你的Machin Catalogs上的名稱定義來作updateclass
$Snapshot = "Citrix_$Today"
Start-Sleep -s 30 ##若是不中止30sec,我這邊的環境會發生帶到兩筆路徑到待會下面的執行變數之中。
$VM = get-childitem -adminaddress "ddc.citrix.com:80" "XDHyp:\HostingUnits\dd\" | where-object {$_.ObjectType -eq 'VM' -and $_.PSChildName -like 'Windows 7 test.vm'} ##抓取Hypervisor中要作母版更新的VM路徑
$VMSnapshot = get-childitem -adminaddress "ddc.citrix.com:80" $VM.FullPath -Recurse -Include *.snapshot ##抓取更新VM機器之中的Snapshot路徑1
$TargetSnapshot = $VMSnapshot | Where-Object {$_.FullName -eq "$snapshot.snapshot"} ##抓取更新VM機器之中的Snapshot路徑2
Set-ProvSchemeMetadata -AdminAddress "ddc.citrix.com:80" -Name "ImageManagementPrep_DoImagePreparation" -ProvisioningSchemeName "TESTSCRIPTS" -Value "True" ##準備更新的process
publish-provMasterVMImage -provisioningSchemeName $ProvSchemeName -MasterImageVM $TargetSnapshot.fullpath -AdminAddress "ddc.citrix.com:80" -RunAsynchronously ##執行更新開始
Start-BrokerNaturalRebootCycle -AdminAddress "ddc.citrix.com:80" -InputObject @("TESTSCRIPTS") ##更新後直接重開
參考網址:
http://stealthpuppy.com/xendesktop-update-mcs-machine-catalog-powershell/