Freigeben über


How To: Update Site Collection Quotas For Existing Site Collections

Setting the default quota template for site collections in a web application is easy enough. But what do you do when you want to change the template associated with some or all of the site collection in a web application? Out of the box, there are no good tools to do this. While we certainly have a UI to manipulate the quota template associated to a site collection, it's a single-site-collection-at-a-time affair - a daunting task when you're dealing with more than even a few site collections.

Take the example of My Sites. When planning your My Site deployment, you'll probably spend good bit of time planning out the storage neccessary to support your end user adoption rate of My Sites, and also spend a fair bit of time discussing how much space (maximum) you want to allow your users to consume. You'll enforce this with a template. But what happens in 6 months, when you decide that your estimates were too high, or too low, and you need to either increase the storage that end users can use, or decrease the storage? Manually adjusting 1000's of site collections would take days!

Enter a wee bit of PowerShell script and the SharePoint 2010 Management Shell. We have to use a few bits of the SharePoint object model to make this work, but this task is simple enough to be approachable by even the most code-averse IT pro's out there:

# Replace all site collection quotas in a web application with a new template$TemplateName = "My Template Name"$WebApplicationUrl = "https://my/"$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService$quotaTemplate = $contentService.QuotaTemplates[$TemplateName]$webApplication = Get-SPWebApplication $WebApplicationUrl$webApplication.Sites | ForEach-Object { try { $_.Quota = $quotaTemplate; } finally { $_.Dispose(); } }

 In the above, just replace "My Template Name" with the name of the new or updated quota template you'd like to assign, and https://my/ with the URL of the web application you'd like updated. This script will replace the quota template on every site collection within that web application.

Too heavy handed for you? What if you only wanted to replace the template assigned to a site collection if it was already assigned a specific template? So, for instance, you've got some sites using a quota template called "Bad Template", but you don't want to use that template anymore, and you want to replace the quota templates assigned to those folks with a new template, "Good Template". What to do?

Enter a nother wee bit of script:

# Replace all site collections having a specific quota template with a new quota template$OldTemplateName = "Bad Template"$NewTemplateName = "Good Template"$WebApplicationUrl = "https://my/"$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService$quotaTemplate = $contentService.QuotaTemplates[$OldTemplateName]$replaceQuotaTemplate = $contentService.QuotaTemplates[$NewTemplateName]$webApplication = Get-SPWebApplication $WebApplicationUrl$webApplication.Sites | ForEach-Object { try { if ($_.Quota.QuotaID -eq $quotaTemplate.QuotaID) { $_.Quota = $replaceQuotaTemplate } } finally { $_.Dispose(); } }

Again, simply replace "Bad Template" with the template you want to replace, "Good Template" with the name of the new template to replace "Bad Template" with, and https://my/ with the URL of the web application you want to process.

But wait! What if you don't want *any* quota templates! How do I remove the quota templates from all sites with a specific quota template already applied? Easy enough:

# Replace all site collections having a specific quota template with a new quota template$OldTemplateName = "Bad Template"$WebApplicationUrl = "https://my/"$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService$quotaTemplate = $contentService.QuotaTemplates[$OldTemplateName]$webApplication = Get-SPWebApplication $WebApplicationUrl$webApplication.Sites | ForEach-Object { try { if ($_.Quota.QuotaID -eq $quotaTemplate.QuotaID) { $_.Quota = $null } } finally { $_.Dispose(); } }

Hope that helps those of you struggling with ex-post-facto updates to site collection quotas!