Skip to content

Instantly share code, notes, and snippets.

Last active July 19, 2017 14:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Gracefully shutdown the Distributed Cache Instance on the server; SharePoint 2013, SharePoint 2016
# Source:
# changed it to dynamic hostname
# Run this on the Cache Host that should be stopped
$hostName = [System.Net.Dns]::GetHostByName(($env:COMPUTERNAME)).HostName
$startTime = Get-Date
$currentTime = $startTime
$elapsedTime = $currentTime - $startTime
$timeOut = 900
try {
Write-Host "Shutting down distributed cache host."
$hostInfo = Stop-CacheHost -Graceful -CachePort 22233 -HostName $hostName
while($elapsedTime.TotalSeconds -le $timeOut-and $hostInfo.Status -ne 'Down')
Write-Host $elapsedTime " sec. - Status: [$($hostInfo.Status)]"
$currentTime = Get-Date
$elapsedTime = $currentTime - $startTime
$hostInfo = Get-CacheHost -HostName $hostName -CachePort 22233
Write-Host "Stopping distributed cache host was successful. Updating Service status in SharePoint."
Write-Host "To start service, please use Central Administration site."
} catch [System.Exception] {
Write-Host "Unable to stop cache host within 15 minutes."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment