Additional “Quick and Dirty” PVS Write Cache / Reboot Idle XenDesktop Scripts


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


Add-PSSnapin Citrix*
[email protected]()
foreach($controller in $siteControllers)
$reg=get-brokerdesktop -MaxRecordCount 9999 -RegistrationState Registered -adminaddress $controller

$reg |where-object {$_.AssociatedUserNames.count -lt 1} | %{
Write-host "Checking $comp ..." -ForegroundColor Yellow
$cache=dir "\\$comp\D`$\vdiskdif.vhdx" -force;
$OS= (gwmi win32_operatingSystem -ComputerName $comp)
$BootTime = $OS.ConvertToDateTime($OS.LastBootUpTime)
$Uptime = $OS.ConvertToDateTime($OS.LocalDateTime) - $boottime
$compResult= New-Object -type PSObject -property @{
'Computer'= $comp
'CacheLength' = $($($cache.length)/1GB)
'Uptime' = $Uptime



You might, instead, want to take said machines that are ready to, or have already, fall(en) over and reboot them.  But we don’t want to nuke machines with users!
asnp Citrix*

foreach ($controller in $siteControllers)
$collection=get-brokerdesktop -maxrecordcount 9999 -adminaddress $controller  | where-object {($_.AssociatedUserNames).Count -lt 1 }
write-host "Got $($collection.count) machines"

$interval=100 #How many machines in a batch.  Limited to XenDesktop power settings, max "actions per minute" under Hosting/Properties/Advanced!
while ($index -lt $collection.count)
$logging=Start-LogHighLevelOperation -Text "Resetting next $interval idle machines to refresh. $index of $($collection.count) " -source "Script" -OperationType AdminActivity -AdminAddress $controller
for (;$index -lt ($indexCheck+$interval) -and $index -lt $collection.Count; $index++)

if( (Get-BrokerMachine -HostedMachineName $($collection[$index]).HostedMachineName -AdminAddress $controller).AssociatedUserNames.Count -lt 1)
write-host "Trying to reset $($($collection[$index]).HostedMachineName)"
New-BrokerHostingPowerAction -Action Reset -MachineName $($collection[$index]).HostedMachineName -AdminAddress $controller -LoggingId $ | Select hostedmachinename,state,requesttime

catch {$LogSuccessResult=$false}
Stop-LogHighLevelOperation -HighLevelOperationId $logging.Id -AdminAddress $controller -IsSuccessful $LogSuccessResult

write-host "Shhh, go to sleep little babe for $seconds seconds" -ForegroundColor Yellow
start-sleep $seconds

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.