Freigeben über


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

If you need to know how to run a graceful shutdown of a distributed cache service instance before restarting the server, with admin right, here is how :

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