A quick way to turn off the Second Stage Recycle Bin in SharePoint 2010 – set the quota to zero. In Central Admin, you cannot set a zero value, but there is an option to turn it off.
foreach ($webApp in Get-SPWebAPplication)
$webApp.SecondStageRecycleBinQuota = 0
Simple enough, and while working on a client site I’ve come across an issue with a particular web application and received the error:
Exception setting "SecondStageRecycleBinQuota": "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
At line:4 char:13
+ $webApp. <<<< SecondStageRecycleBinQuota = 0
+ CategoryInfo : InvalidOperation: (:) , RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Both in PowerShell and in Central Admin, I was able to set the quota for the second stage recycle bin to as low as 1%, but not turn it off. In Central Admin, I was getting this error:
After turning on verbose logging, this error was picked up:
Access Denied for /_admin/vsgeneralsettings.aspx?type=gen&WebApplicationId=707dac5e9db64a96b509c5f153ace591&IsDlg=1. StackTrace:
at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(HttpContext context)
at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex)
at Microsoft.SharePoint.Library.SPRequest.GetAdminRecycleBinItems(String bstrSiteUrl, Object& pvarItems, UInt32& pdwNumberOfItems)
It appeared that the logged in account did not have access to the recycle bin to remove the contents. This was not a problem for other Web Applications, and did not use the Farm Service Account as I expected. Granting the logged in account with Full Control to the Web Application User Policy for the problematic Web Application allowed me to turn off the second stage recycle bin with both PowerShell and Central Admin. I can only presume the logged in account already had access to the other Web Applications which is why they worked.