How to run a graceful shutdown of a Distributed Cache Service instance before restarting the server

Add-PSSnapin *
Use-CacheCluster
Get-CacheHost
Stop-SPDistributedCacheServiceInstance -Graceful
function Read_AFCacheStatistics {
$AFCacheStatistics = Get-AFCacheHostStatus | % {
$ServerName = $_.HostName.ToLower()
$hostname = $env:COMPUTERNAME.ToLower()
if ($ServerName -match $hostname){
Get-AFCacheStatistics -ComputerName $_.HostName -CachePort $_.PortNo | Add-Member -MemberType NoteProperty -Name 'ServerName' -Value $ServerName -PassThru
}
}
return $AFCacheStatistics.Size }
while (Read_AFCacheStatistics -ge 0) {
$Cache_Size = Read_AFCacheStatistics
Write-Host "Current cache size is:" -NoNewline; Write-Host $Cache_Size
}
Remove-SPDistributedCacheServiceInstance

 

Leave a Reply

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