Programatically setting Site Quota Templates Programatically setting Site Quota Templates
Hiren Senjaliya

Hiren Senjaliya

September 04, 2012

All Post
Programatically-setting-Site-Quota-Templates
Share:

Setting Site Quota Templates using PowerShell

Once sites are created, it can be a challenge to change the quota template. Here’s a way to rip through your site collections and change the quota. In the script below, I grab the Web Application, and go through all the Site Collections, but filter on them using -Match. The trick is to first ensure you are using the Content Service associated with the web application.

   $TemplateName = "MyQuota"
$webAppName = "http://yourWebApp"
$webApplication = Get-SPWebApplication $webAppName
$sFilter = "$($webAppName)/MyPath*"
 
$TemplateName = "MyQuotaTemplate"
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$TemplateName]
 
if ($quotaTemplate -ne $null)
{
$ss = $webApplication.Sites 
$sCount = $ss.count
for ($i =0; $i -lt $sCount; $i++)
{
    $site = $ss[$i];
    if ($site.url -match $sfilter)
    {
        try
        {
            $site.set_Quota($quotaTemplate)
            Write-Host "Set Quota for $($site.url)"
        }
        catch
        {
            Write-Host -ForegroundColor DarkRed "Error setting Quota for $($site.url)"
        }
    }
    $site.dispose()
}
}

One thought on “Programatically setting Site Quota Templates

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to talk?

Drop us a line. We are here to answer your questions 24*7.