Saturday, August 31, 2013

Change SharePoint Site Collection Quota using PowerShell

In some cases, I have seen site collection quotas are turned to "Individual Quota" in database attachment method, even I copied the quota templates before database attachment. All quota settings are lost! I dunno the cause of this issue and want to apply site collection quota to existing sites.

To apply quota for SharePoint site collection using PowerShell, the syntax goes like:
Set-SPSite -Identity "Site-collection-URL" -QuotaTemplate "Quota-Template-Name"

E.g.

Set-SPSite -Identity "http://sharePoint.company.com/sites/sales" -QuotaTemplate "Gold - 1 GB"
Where "Gold - 1 GB" is our existing quota defined! We can apply quotas in bulk with PowerShell now!

Change quota for SharePoint Site Collections programmatically:
To set site collection quota for SharePoint sites programmatically using PowerShell, The code goes like:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Void]System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") 

function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }

$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService

$QuotaTemplate = $contentService.QuotaTemplates["Gold - 1 GB"]
$site = Get-SPSite "http://sharepoint.company.com/"
$site.quota=$QuotaTemplate 

Set Individual Quotas using PowerShell:
#Set the site URL variable accordingly!
$SiteURL = "http://sales.crescent.com"

Set-SPSite -Identity $SiteURL -MaxSize 1GB -WarningSize 900MB 

Bulk update SharePoint Site collection quotas:
In an another case, Got a requirement to change quota template for all site collections under a specific managed path (say: Departments)
$WebAppURL = "http://sharepoint.crescent.com"

$TemplateName ="Gold - 1 GB"

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$TemplateName]

Get-SPWebApplication $WebAppURL | Get-spsite -limit all | Where-Object {$_.ServerRelativeUrl.StartsWith("/departments/")} |  ForEach-Object { $_.Quota = $quotaTemplate }

SharePoint 2007 - Set quotas in Bulk with STSADM:
We can set site collection quota in bulk using stsadm -o updatequota command line. Its available after installing SharePoint Administration Toolkit version 4.0

E.g. stsadm –o updatequota –quotaname "Name of the Quota defined in Central Admin" 
Its also possible to limit the quota changes with in a content database. More info: http://technet.microsoft.com/en-us/library/ee449569%28v=office.12%29.aspx  



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Five Challenges in SharePoint Security
...And How to Solve Them. Free White Paper
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...