I'm trying to enable and configure output cache on a site collection with Powershell. But I get an Access denied when running the script.
Exception calling "Update" with "0" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
I'm running the following script and it fails on $cacheSettings.Update():
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$cacheSettings = new-object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter("http://siteaddress")
$cacheSettings.EnableCache
$cacheSettings.EnableCache = $true
$cacheSettings.Update()
I'm runing the script with a user that I thought had all the necessary permissions but obviously not. I gave the user permissions with the following command:
Get-SPDatabase | Add-SPShellAdmin mydomain\user
I executed the Add-SPShellAdmin-command with my install-account without any errors. mydomain\user is also site collection administrator for http://siteaddress.
So, what permission am I missing to run the script?