Calculate and Set Distributed Cache Size

#calculation from:

$membanks =get-wmiobject Win32_PhysicalMemory

$sum = 0


foreach ($membank in $membanks)


 write-host "Capacity Memory $i = " ($membank.capacity/1024/1024)

 $sum = ($membank.capacity/1024/1024) + $sum




write-host "Sum of Memory = " $sum


$cachesize = ($sum - 2048)/2

if ($cachesize>16384)


  $cachesize=16384 #not more than 16GB



write-host "Distributed Cachesize will be updated to: " $cachesize

Update-SPDistributedCacheSize -CacheSizeInMB $cachesize

Comments (6)

  1. C. T. Haun says:

    Works well. It might be good to point out that this is mainly useful for servers that are going to be dedicated Distributed Cache servers. And you might want to leave more than 2 GB for the OS because you may have backup jobs and antivirus process and
    other processes that might want a little RAM too. For SharePoint servers that are not dedicated to distributed cache duties, the guidance at still says the recommended cache size is 1 GB for a small farm (less than 10,000 users), is 2.5 GB for a medium farm (less than
    100,000 users), and 12 GB for a large farm (less than 500,000 users).

  2. Jon says:

    PS typo in script. Should be: if ($cachesize -gt 16384)

  3. Brent Harvey says:

    Handy tip.
    Instead of the ” / 1024 /1024″ , you can just change it to ” / 1MB” to convert to MB. (Ditto for GB, etc.)

  4. Nik Patel says:

    One more note for readers of this blog, Please stop Distributed Cache service on all servers in farm, Run this script from only 1 server in farm, and Start Distributed Cache service on required servers in farm.

  5. Nik Patel says:

    Nicely automated script to set DS memory max to 16 GB.. How about stopping servers and starting Distributed Cache service on server before and after setting cache size? How about supporting this script for multiple cache host in servers? Please don't take this as critical comment.. Overall, you have done great job posting this script. I may able to extend your script to some of the concerns I have mentioned in this comment…

  6. Hi Nik,

    Doing that on all servers from one PS Window could be a little tricky, because I have to check if PS Remoting is correctly configured, FW Ports are open….

    Stopping and Starting is a great idea. I'll change the script here as soon as I've time!

Skip to main content