{"id":4519,"date":"2016-12-29T22:43:30","date_gmt":"2016-12-30T06:43:30","guid":{"rendered":"https:\/\/www.atumvirt.com\/?p=4519"},"modified":"2016-12-29T22:43:30","modified_gmt":"2016-12-30T06:43:30","slug":"additional-quick-and-dirty-pvs-write-cache-reboot-idle-xendesktop-scripts","status":"publish","type":"post","link":"https:\/\/avtempwp.azurewebsites.net\/2016\/12\/additional-quick-and-dirty-pvs-write-cache-reboot-idle-xendesktop-scripts\/","title":{"rendered":"Additional “Quick and Dirty” PVS Write Cache \/ Reboot Idle XenDesktop Scripts"},"content":{"rendered":"

 <\/p>\n

A few years ago I had an issue where I needed to check the size of .vdiskcache.\u00a0 Times have changed and now instead of \u201c.vdiskcache\u201d we have \u201c.vhdx\u201d with our snazzy new \u201cCache in RAM with overflow\u201d write cache option.\u00a0 Here we have an updated better version.\u00a0 You can output $results to something nice (like export-csv or something else).<\/p>\n

 <\/p>\n

Add-PSSnapin Citrix*\n$siteControllers=\"site1Controller\"\n$results=@()\nforeach($controller in $siteControllers)\n{\n$reg=get-brokerdesktop -MaxRecordCount 9999 -RegistrationState Registered -adminaddress $controller\n\n$reg |where-object {$_.AssociatedUserNames.count -lt 1} | %{\n$comp=$_.hostedmachinename;\nWrite-host \"Checking $comp ...\" -ForegroundColor Yellow\n$cache=dir \"\\\\$comp\\D`$\\vdiskdif.vhdx\" -force;\n$OS= (gwmi win32_operatingSystem -ComputerName $comp)\n$BootTime = $OS.ConvertToDateTime($OS.LastBootUpTime)\n$Uptime = $OS.ConvertToDateTime($OS.LocalDateTime) - $boottime\n$compResult= New-Object -type PSObject -property @{\n'Computer'= $comp\n'CacheLength' = $($($cache.length)\/1GB)\n'Uptime' = $Uptime\n}\n$results+=$compResult\n\n}\n}\n<\/pre>\n

 <\/p>\n

You might, instead, want to take said machines that are ready to, or have already, fall(en) over and reboot them.\u00a0 But we don\u2019t want to nuke machines with users!
\nasnp Citrix*<\/p>\n

$siteControllers=\"site1Controller\",\"site2Controller\"\nforeach ($controller in $siteControllers)\n{\n$collection=get-brokerdesktop -maxrecordcount 9999 -adminaddress $controller\u00a0 | where-object {($_.AssociatedUserNames).Count -lt 1 }\nwrite-host \"Got $($collection.count) machines\"\n\n$interval=100 #How many machines in a batch.\u00a0 Limited to XenDesktop power settings, max \"actions per minute\" under Hosting\/Properties\/Advanced!\n$seconds=30\n$index=0\n$indexCheck=0\nwhile ($index -lt $collection.count)\n{\n$LogSuccessResult=$false\n$logging=Start-LogHighLevelOperation -Text \"Resetting next $interval idle machines to refresh. $index of $($collection.count) \" -source \"Script\" -OperationType AdminActivity -AdminAddress $controller\ntry{\nfor (;$index -lt ($indexCheck+$interval) -and $index -lt $collection.Count; $index++)\n{\n\n\nif( (Get-BrokerMachine -HostedMachineName $($collection[$index]).HostedMachineName -AdminAddress $controller).AssociatedUserNames.Count -lt 1)\n{\nwrite-host \"Trying to reset $($($collection[$index]).HostedMachineName)\"\nNew-BrokerHostingPowerAction -Action Reset -MachineName $($collection[$index]).HostedMachineName -AdminAddress $controller -LoggingId $logging.id | Select hostedmachinename,state,requesttime\n}\n\n}\n$LogSuccessResult=$true\n}\ncatch {$LogSuccessResult=$false}\nStop-LogHighLevelOperation -HighLevelOperationId $logging.Id -AdminAddress $controller -IsSuccessful $LogSuccessResult\n\nwrite-host \"Shhh, go to sleep little babe for $seconds seconds\" -ForegroundColor Yellow\nstart-sleep $seconds\n$indexCheck=$index\n}\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

  A few years ago I had an issue where I needed to check the size of .vdiskcache.\u00a0 Times have changed and now instead of \u201c.vdiskcache\u201d we have \u201c.vhdx\u201d with our snazzy new \u201cCache in RAM with overflow\u201d write cache option.\u00a0 Here we have an updated better version.\u00a0 You can output $results to something nice […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts\/4519"}],"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=4519"}],"version-history":[{"count":0,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts\/4519\/revisions"}],"wp:attachment":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/media?parent=4519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/categories?post=4519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/tags?post=4519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}