Archive for June, 2011

I believe I got the base of this script from the AutoSPInstaller Project on CodePlex. I enhanced it to enable object cache on all web apps. Just fill in your variables on lines 1 and 2. *Note many of my customers tend to create long user names for these two accounts. Make sure to get the Pre-Compatibility 2000 username, its will be shoter in length than the full username. The script will blow up if you use the longer one. Thanks.

 

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
$SuperUserAcc = "domain\SPSObjectCacheF"
$SuperReaderAcc = "domain\SPSObjectCacheR"
 
$PortalName = Get-SPWebApplication | select DisplayName
 
function Set-WebAppUserPolicy($webApp, $userName,$displayName, $perm) {
    [Microsoft.SharePoint.Administration.SPPolicyCollection]$policies = $webApp.Policies
    [Microsoft.SharePoint.Administration.SPPolicy]$policy = $policies.Add($userName, $displayName)
    [Microsoft.SharePoint.Administration.SPPolicyRole]$policyRole = $webApp.PolicyRoles | where {$_.Name -eq $perm}
    if ($policyRole -ne $null) {
        $policy.PolicyRoleBindings.Add($policyRole)
    }
    $webApp.Update()
}
 
function ConfigureObjectCache
{
	foreach ($p in $PortalName)
	{
		$site = $p.DisplayName
		Try
		{
   			Write-Host -ForegroundColor White "- Applying object cache..."
        		$webapp = Get-SPWebApplication | ? {$_.DisplayName -eq $p.Displayname}
 
        		If ($webapp -ne $Null)
        		{
				Write-Host -ForegroundColor White " - Applying object cache to $site ..."
           			$webapp.Properties["portalsuperuseraccount"] = $SuperUserAcc
	       			Set-WebAppUserPolicy $webApp $SuperUserAcc "Super User (Object Cache)"  "Full Control"
 
           			$webapp.Properties["portalsuperreaderaccount"] = $SuperReaderAcc
	       			Set-WebAppUserPolicy $webApp $SuperReaderAcc "Super Reader (Object Cache)" "Full Read"
           			$webapp.Update()        
    	   			write-Host -ForegroundColor White "- Done."
        		}
		}
		Catch
		{
			$_
			Write-Warning "- An error occurred applying object cache to portal."
		}
	}
}
 
ConfigureObjectCache
  • Archives

  • Tags

  • Subscribe
  • Pages

  • More

  • Disclaimer…

    This is my personal weblog. The opinions expressed herein are my own and are not representative of any 3rd party influence. The owner of this blog reserves the right to edit or delete any comments submitted to this blog without notice if they are deemed to be spam, offensive or otherwise inappropriate. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.


    Lastly, I do my best to document my sources if the article is not of my own creation. If I have missed or forgotten to source your work. I would love feedback via the comments section. Thank you.

DreamHost promos
SiteLock