Some Powershell examples of getting AppFabric Distributed Cache Instances.
Work-in-progress article…
Basic Cluster Info:
1 2 3 4 5 |
$SPFarm = Get-SPFarm $cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString() $cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local $cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName); $cacheClusterInfo.CacheHostsInfoCollection |
CacheStatistics per CacheHost
1 |
Get-CacheHost | %{$HostName = $_.HostName;Get-CacheStatistics -ComputerName $HostName -CachePort $_.PortNo | Add-Member -MemberType NoteProperty -Name 'HostName' -Value $HostName -PassThru} |
CacheStatistics per NamedCache
1 |
Get-Cache | %{$CacheName = $_.CacheName;Get-CacheStatistics $CacheName | Add-Member -NotePropertyName "CacheName" -NotePropertyValue $CacheName -PassThru} |
Very Basis Cache Cluster Info:
1 2 3 |
$Provider = "SPDistributedCacheClusterProvider" $ConnectionString = (Get-SPDatabase | ?{$_.Type -match "Configuration"}).DatabaseConnectionString Get-CacheClusterInfo -ProviderType $Provider -ConnectionString $ConnectionString |
Advanced CacheHost Status, where Distributed Cache resides on all SharePoint Front-End servers which do not host the Central Administration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#Status Defaults $TxtStatusArr = @("OK","WARN","CRIT") #Determine servers #We assume AppFabric Distributed Cache is activated on the Front-End servers $SharePointServers = @(Get-SPServer | ?{$_.Role -eq "Application"} | %{$_.Name}) #Handle all-in-one development server If (@($SharePointServers).Count -eq 1){ $FrontEndServers = @($SharePointServers) }Else{ $WebAppServers = @(Get-SPServiceInstance | ?{$_.TypeName -eq "Microsoft SharePoint Foundation Web Application"} | ?{$_.Status -eq "Online"} | %{$_.Server.Name}) $BackEndServers = @(Get-SPServiceInstance | ?{$_.TypeName -eq "Central Administration"} | ?{$_.Status -eq "Online"} | %{$_.Server.Name}) $FrontEndServers = @(Get-SPServer | ?{$_.Role -eq "Application"} | %{$_.Name} | ?{$_ -NotIn $BackEndServers}) #Handle farm where Central Admin is hosted on every SP Server If (@($FrontEndServers).Count -eq 0){ $FrontEndServers = @($BackEndServers) } } #AppFabricDistributedCache check $CheckName = "SP_DistributedCache_CacheHosts" $ResultStatus = 1 Try{ $CacheServices = @(Get-SPServiceInstance | ?{$_.TypeName -eq "Distributed Cache"}) Use-CacheCluster $CacheHosts = @(Get-CacheHost -ErrorAction:SilentlyContinue) If ( $CacheServices.Count -eq $FrontEndServers.Count ){ #CacheServiceCount If ( @($CacheServices | ?{$_.Status -eq "Online"}).Count -eq $CacheServices.Count){ #CacheServiceStatus If ( $CacheHosts.Count -eq $CacheServices.Count ){ #CacheHostsCount If ( @($CacheHosts | ?{$_.Status -eq "Up"}).Count -eq $CacheServices.Count){ #CacheHostsStatus $ResultTxt = "All cache hosts are OK" $ResultStatus = 0 }Else{ #CacheHostsStatus $FailedCacheHosts = @($CacheHosts | ?{$_.Status -ne "Up"} | %{ @($_.Hostname,$_.Status) -Join ":" }) -Join "," $ResultTxt = "Some cache hosts in down status: $FailedCacheHosts" } }Else{ #CacheHostsCount $FailedCacheHosts = @($FrontEndServers | ?{$_ -NotIn @($CacheServices).Server.Name}) $ResultTxt = "Some FrontEnd servers do not have the cache host: $FailedCacheHosts" } }Else{ #CacheServiceStatus $FailedCacheHosts = @($CacheServices | ?{$_.Status -ne "Online"} | %{ @($_.Server.Name,$_.Status) -Join ":" }) -Join "," $ResultTxt = "Some cache services in down status: $FailedCacheHosts" } }Else{ #CacheServiceCount $FailedCacheHosts = @($FrontEndServers | ?{$_ -NotIn @($CacheServices).Server.Name}) $ResultTxt = "Some FrontEnd servers do not have the cache service: $FailedCacheHosts" } }Catch{ $ResultTxt = $_.Exception.Message $ResultStatus = 2 } Write-Host "$ResultStatus $CheckName $($TxtStatusArr[$ResultStatus]) - $ResultTxt" |
Different examples of Cache Configuration
Cache Allowed Clients should always return the default by SharePoint created and populated groups
1 2 3 |
PS C:\> Get-CacheAllowedClientAccounts WSS_ADMIN_WPG WSS_WPG |
CacheClient Configuration might seem difficult to interpret when using the command Get-SPDistributedCacheClientSetting, however using the .NET namespaces it is translated to human readable time values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache ChannelInitializationTimeout : 60000 ConnectionBufferSize : 131072 MaxBufferPoolSize : 268435456 MaxBufferSize : 8388608 MaxOutputDelay : 2 ReceiveTimeout : 60000 ChannelOpenTimeOut : 20 RequestTimeout : 20 MaxConnectionsToServer : 2 [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local.GetSPDistributedCacheClientConfigurationSettings('DistributedLogonTokenCache') ChannelInitializationTimeout : 00:01:00 ConnectionBufferSize : 131072 MaxBufferPoolSize : 268435456 MaxBufferSize : 8388608 MaxOutputDelay : 00:00:00.0020000 ReceiveTimeout : 00:01:00 ChannelOpenTimeOut : 00:00:00.0200000 RequestTimeout : 00:00:00.0200000 MaxConnectionsToServer : 2 UpgradedPersistedProperties : {} |