Create Policies for Sharepoint and Powershell 1.0

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Sharepoint”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Sharepoint.Publishing”)


$SiteURL = “http://www.example.com
$site = new-object Microsoft.SharePoint.SPSite($siteURL)
$web = $site.OpenWeb()
$list = $web.Lists[“Cache Profiles”]
$newitem = $list.items.Add()
$newitem[“Title”]= “AnonCachePolicy”
$newitem[“Display Name”]= “AnonCachePolicy”
$newitem[“Display Description”]= “AnonCachePolicy”
$newitem[“Perform ACL Check”] = $false
$newitem[“Enabled”] = $true
$newitem[“Duration”] = 60
$newitem[“Check for Changes”] = $false
$newitem[“Vary by HTTP Header”] = “User-Agent”
$newitem[“Vary by User Rights”] = $false
$newitem[“Cacheability”] = “ServerAndPrivate”
$newitem[“Safe for Authenticated Use”] = $false
$newitem[“Allow writers to view cached content”] = $false
$newitem.update()


$anonID = ($list.items | where {$_.Name -eq “AnonCachePolicy”}).ID


$newitem = $list.items.Add()
$newitem[“Title”]= “AuthCachePolicy”
$newitem[“Display Name”]= “AuthCachePolicy”
$newitem[“Display Description”]= “AuthCachePolicy”
$newitem[“Perform ACL Check”] = $true
$newitem[“Enabled”] = $true
$newitem[“Duration”] = 60
$newitem[“Check for Changes”] = $true
$newitem[“Vary by HTTP Header”] = “HTTP_USER”
$newitem[“Vary by User Rights”] = $false
$newitem[“Cacheability”] = “ServerAndNoCache”
$newitem[“Safe for Authenticated Use”] = $true
$newitem[“Allow writers to view cached content”] = $false
$newitem.update()


$authID = ($list.items | where {$_.Name -eq “AuthCachePolicy”}).ID


$cacheSettings = new-object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter($site)
$cacheSettings.EnableCache = $true
$cacheSettings.ObjectCacheSize = 200
$cacheSettings.SetAnonymousPageCacheProfileId($site, $anonID)
$cacheSettings.SetAuthenticatedPageCacheProfileId($site, $authID)
$cacheSettings.Update()


$web.Dispose()
$site.Dispose()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s