Programatically setting Site Quota Templates

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()
}
}
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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