Calculate and Set Distributed Cache Size

#calculation from: http://technet.microsoft.com/en-us/library/jj219613.aspx

$membanks =get-wmiobject Win32_PhysicalMemory

$sum = 0

$i=1

foreach ($membank in $membanks)

{

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

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

 $i=$i+1

}

 

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