Set SharePoint cache accounts with PowerShell

The object cache stores properties about items in SharePoint Server 2010/2013. Items in this cache are used by the publishing feature when it renders web pages. The goals of the object cache are to reduce the load on the computer on which SQL Server is running, and to improve request latency and throughput. The object cache makes its queries as one of two out-of-box user accounts: the Portal Super User and the Portal Super Reader (SharePoint cache accounts). These SharePoint cache accounts must be properly configured to ensure that the object cache works correctly. The Portal Super User account must be an account that has Full Control access to the web application. The Portal Super Reader account must be an account that has Full Read access to the web application.
http://technet.microsoft.com/en-us/library/ff758656(v=office.15).aspx

You can use the below script to automatically grant the cache accounts the required permissions and add these for all web applications.

$webapps = Get-SPWebApplication
$SuperUserAcc = “i:0#.w|peet\sp2013_superuser”
$SuperReaderAcc = “i:0#.w|peet\sp2013_superreader”
foreach($webapp in $webapps)
{
[Microsoft.SharePoint.Administration.SPPolicyCollection]$policies = $webapp.Policies
[Microsoft.SharePoint.Administration.SPPolicy]$policy = $policies.Add($SuperUserAcc, "Super User (Object Cache)")
[Microsoft.SharePoint.Administration.SPPolicyRole]$policyRole = $webapp.PolicyRoles | where {$_.Name -eq "Full Control"}
$policy.PolicyRoleBindings.Add($policyRole)
[Microsoft.SharePoint.Administration.SPPolicy]$policy = $policies.Add($SuperReaderAcc, "Super Reader (Object Cache)")
[Microsoft.SharePoint.Administration.SPPolicyRole]$policyRole = $webapp.PolicyRoles | where {$_.Name -eq "Full Read"}
$policy.PolicyRoleBindings.Add($policyRole)
$webapp.properties["portalsuperuseraccount"] = $SuperUserAcc
$webapp.properties["portalsuperreaderaccount"] = $SuperReaderAcc
$webapp.Update()
}

image

image

Leave a Reply

Your email address will not be published. Required fields are marked *