{"id":2331,"date":"2013-12-18T15:12:40","date_gmt":"2013-12-18T23:12:40","guid":{"rendered":"http:\/\/www.atumvirt.com\/?p=2331"},"modified":"2013-12-18T15:12:40","modified_gmt":"2013-12-18T23:12:40","slug":"automating-xendesktop-ilio-storage-reboots","status":"publish","type":"post","link":"https:\/\/avtempwp.azurewebsites.net\/2013\/12\/automating-xendesktop-ilio-storage-reboots\/","title":{"rendered":"Automating XenDesktop, ILIO Storage Reboots"},"content":{"rendered":"
We use XenDesktop 7 and Atlantis ILIO Diskless for our VDI environment. ILIO functions as a storage device. \u00a0The ILIO VM should occasionally be rebooted per the documentation, or the datastore can fill over time. \u00a0The script below is what we use to reboot our VMs daily, and the ILIO devices every other day. \u00a0Depending on utilization, you can go much longer so do test and follow your documentation.<\/p>\n
<\/p>\n
$dateTime=get-date\n$ScriptName=\"VMReboot\"\n$BrokerGroupName=\"YourBrokerGroupName\"\n$vCenterAddress=\"YourvCenterServer\"\n$oddHosts=\"Your hosts here\"\n$evenHosts=\"Your hosts here\"\n$VMNameWildcard=\"YourVDIVMName\" # example: VDI*\n$ILIOvmName=\"Your ILIO VM name here\"\n\n$citrixAdminAddress = \"\" #TODO: get all delivery controllers, select random active one\nStart-Transcript -path C:Scriptslogs$ScriptName$ScriptName_$($datetime.tostring(\"yyyy-MM-dd-hh_mm_ss\")).log -Append -Confirm:$false\n Function check-even ($num) {[bool]!($num%2)}\n\n if($datetime.Hour -eq 2)\n {\n\n Add-PSSnapin Citrix*\n Add-PSSnapin VMware.VimAutomation.Core\n\n [bool]$disableMaintOnCompletion=$true\n write-host \"Connecting to $vCenterAddress\"\n Connect-VIServer -Server $vCenterAddress #-Credential $credential -ErrorAction Stop ## Running task as service account...don't need creds\n Get-BrokerDesktopGroup $BrokerGroupName -adminaddress $citrixAdminAddress | Set-BrokerDesktopGroup -InMaintenanceMode:$true\n\n $vmHosts=@()\n if(check-even $datetime.Day) \n { \n $evenHosts | %{ $vmhosts+=Get-VMHost -Name \"$_*\" } \n } \n else\n { \n $oddHosts | %{ $vmhosts+=Get-VMHost -Name \"$_*\" } \n }\n\n ## First lets loop through all the hosts and shutdown off all vms\n\n $vmHosts| % {\n $currentHost=$_\n write-host \"Working on $($currentHost.name)\"\n $vmsOnHost=$currentHost | Get-VM -Name $VMNameWildcard | % {\n #Loop through each VM to shutdown\n $currentVM=$_\n Write-Host \"vSphereDesktop: $($currentVM.Name)\"\n Write-Host \"$(get-date -format \"hh:mm:dd\") Shutting down vSphereDesktop: $($currentVM.Name)\"\n $currentVM | where{$_.PowerState -eq \"PoweredOn\"} | shutdown-VMguest -Confirm:$false -ErrorAction SilentlyContinue\n\n $currentVM=$null\n $brokerDesktop=$null \n\n \t\t}\n\twrite-host \"Sleeping 20sec before forcing shutdown\"\n Start-Sleep 20\n\n $vmsOnHost=$currentHost | Get-VM -Name $VMNameWildcard | % {\n #Loop through each VM to power it off, just in case\n $currentVM=$_\n Write-Host \"vSphereDesktop: $($currentVM.Name)\"\n Write-Host \"$(get-date -format \"hh:mm:dd\") Stopping vSphereDesktop: $($currentVM.Name)\"\n $currentVM | where{$_.PowerState -eq \"PoweredOn\"} | Stop-VM -RunAsync -Confirm:$false -ErrorAction SilentlyContinue\n\n $currentVM=$null\n $brokerDesktop=$null \n\n }\n\n write-host \"Sleeping 1 min before rebooting ILIO\"\n Start-Sleep 60\n\n #Now we need to turn off ILIO\n $ilioVM=$currentHost | get-vm -Name $ilioVMName\n write-host \"$(get-date -format \"hh:mm:dd\") Found $($ilioVM.name), restarting\"\n $ilioVM | Restart-VMGuest -Confirm:$false\n $currentHost=$null\n $vmsOnHost=$null\n $ilioVM=$null\n\t}\n\n write-host \"Sleeping 3 min\"\n Start-Sleep 180\n if($disableMaintOnCompletion)\n {\n\t Get-BrokerDesktopGroup $VMNameWildcard -adminaddress $citrixAdminAddress | Set-BrokerDesktopGroup -InMaintenanceMode:$false\n\n }\n\n else { write-host \"skipping disable maintenance mode\" }\n Disconnect-VIServer $vCenterAddress -Confirm:$false\n }\n else\n {\n Write-Host \"$(get-date -format \"hh:mm:dd\") ERROR: Incorrect hour of day\"\n }\nStop-Transcript<\/pre>\n","protected":false},"excerpt":{"rendered":"We use XenDesktop 7 and Atlantis ILIO Diskless for our VDI environment. ILIO functions as a storage device. \u00a0The ILIO VM should occasionally be rebooted per the documentation, or the datastore can fill over time. \u00a0The script below is what we use to reboot our VMs daily, and the ILIO devices every other day. \u00a0Depending […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,40,50,64,77],"tags":[],"_links":{"self":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts\/2331"}],"collection":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/comments?post=2331"}],"version-history":[{"count":0,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts\/2331\/revisions"}],"wp:attachment":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/media?parent=2331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/categories?post=2331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/tags?post=2331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}