Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We are planning to apply quotas on our site collections of about 60 which are already created in our web application . i thought of achieving that using power shell but we are facing a small problem which is in that 60 site collections i can keep quotas on only 40 site collections as the other 20 will grow rapidly everyday.The only way that i can see the difference is that the managed path of these site collections are different .can anyone please tell me how can i set the quota on a site collection only if it has a manged path 'projects'and leave those which have managed path called 'communities'

Thanks

My Code Up to now

   function CreateQuotaTemplate ($Name, $MaxLevelMB, $WarnLevelMB)
    {
    $quotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
    $quotaTemplate.Name = $Name
    $quotaTemplate.StorageMaximumLevel = ($MaxLevelMB*1024)*1024
    $quotaTemplate.StorageWarningLevel = ($WarnLevelMB*1024)*1024
    $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
    $contentService.QuotaTemplates.Add($quotaTemplate)
    $contentService.Update()
    }

    CreateQuotaTemplate –Name “Power” –MaxLevelMB 300 –WarnLevelMB 280



 # Replace all site collection quotas in a web application with a new template
$TemplateName = "Power"
$WebApplicationUrl = "http://myportal/"

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$TemplateName]
$webApplication = Get-SPWebApplication $WebApplicationUrl
$webApplication.Sites | ForEach-Object { try { $_.Quota = $quotaTemplate; } finally { $_.Dispose(); } }
share|improve this question
    
Can you post the script you have so far? –  Dave Wise Jun 19 '12 at 19:26
    
Hi Dave i just edited my question and added my code –  Anil Jun 19 '12 at 19:34
    
This looks like it only sets the quota on the root site collection. Where is your code to iterate through the other site collections in the web application? –  Dave Wise Jun 19 '12 at 19:42
    
Sorry Dave i added the wrong function now i added the bulk function.. –  Anil Jun 19 '12 at 19:50
add comment

2 Answers

up vote 4 down vote accepted

Inside your try {} block, you might need something like this to check the URL and only apply the quota to the ones you want.

if ($_.ServerRelativeUrl.ToLower().StartsWith("/projects/")) {
   $_.Quota = $quotaTemplate;
}
share|improve this answer
    
HI Dave I am getting the following error can you help me........... Method invocation failed because [System.String] doesn't contain a method named 'ToLowerCase'. At C:\Users\mosssqlservicet\Desktop\Test PowershellScripts\SetQoutaforSC.ps1:29 char:40 + if ($_.ServerRelativeUrl.ToLowerCase <<<< ().StartsWith("/communities/")) { + CategoryInfo : InvalidOperation: (ToLowerCase:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound –  Anil Jun 19 '12 at 20:48
    
Sorry about that, it should be just .ToLower() –  Dave Wise Jun 19 '12 at 20:56
    
Thank you very much Dave it worked perfectly..... –  Anil Jun 19 '12 at 20:59
add comment

Replace the bottom two lines with something like:

get-spwebapplication $WebApplicationUrl | 
  Get-spsite -limit all | 
  Where-Object {$_.ServerRelativeUrl.StartsWith("/projects/")} |
  ForEach-Object { $_.Quota = $quotaTemplate }
share|improve this answer
    
Thanks you very much per.... –  Anil Jun 19 '12 at 20:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.