Whilst you can enforce disk quotas on any site collection in SharePoint, I have seen them used most commonly to cap the amount of disk space used in My Sites. Providing a default site quota template from which all My Sites inherit during creation is easy enough, but it can be a pain for administrators to change the template on existing My Sites as the interface used to modify quota templates on site collections is fine for the odd one or two, but there are no options in the SharePoint UI to bulk modify the quota template used on multiple sites. In this article I will explain how to use PowerShell with SharePoint 2010 to create a new quota template, apply it to a single site collection, and then multiple site collections in one hit.
First, run this script below to set up a function for creating new quota templates:
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()
}
Once you have run the script, type the following command to create a new quota template in your SharePoint farm:
CreateQuotaTemplate –Name “Template Name” –MaxLevelMB MaximumLevelInMB –WarnLevelMB WarningLevelInMB
For example, if we wanted to create a new quota template called “Media Users” with a maximum quota size of 500 MB and warning level of 400 MB, then we can type this command:
CreateQuotaTemplate –Name “Media Users” –MaxLevelMB 500 –WarnLevelMB 400
Now run this script to set up a function for assigning a quota template to a single site collection:
function AssignQuotaTemplate ($Name, $Url)
{
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$Name]
Set-SPSite -Identity $Url -QuotaTemplate $quotaTemplate
}
Once this script has been run, you can now use the following command to assign our “Media Users” quota template to a single site collection:
AssignQuotaTemplate –Name “Media Users” –Url http://mysite/personal/phil.childs
Finally, run this script to set up a function for replacing a quota template across all site collections in a web application:
function BulkReplaceQuotaTemplates ($WebApp, $OldTemplate, $NewTemplate)
{
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$oldQuotaTemplate = $contentService.QuotaTemplates[$OldTemplate]
$newQuotaTemplate = $contentService.QuotaTemplates[$NewTemplate]
$webApplication = Get-SPWebApplication $WebApp
$webApplication | Get-SPSite -limit all | ForEach-Object {
if ($_.Quota.QuotaID -eq $oldQuotaTemplate.QuotaID) {
Set-SPSite -Identity $_.Url -QuotaTemplate $newQuotaTemplate
}
}
}
This function allows you to specify the web application, old quota template you want to replace, and the new quota template you want to replace it with. For example, lets assume that all My Sites in your SharePoint implementation have been created with the default “Personal Site” quota template. We could run a script to simply bulk change all of these site collections to a new quota template, but there may be the odd one or two that have been configured with individual quotas. Therefore, the command below will walk through each site collection in the web application and change the quota template to “Media Users”, but only on site collections that are currently configured with the “Personal Site” quota template – leaving alone any site collections that have been configured with individual quota templates:
BulkReplaceQuotaTemplates -WebApp http://mysite -OldTemplate "Personal Site" -NewTemplate "Media Users”
Hi, Thank you for your script but i can't do it on my 2007 Farm. The command Set-SPSite isn't reconized. Have you an idea ?
ReplyDeleteNicolas LAVOLO
France
You should be able to do the same thing by setting up a $spsite variable from a new SPSite object (see an example at http://nickgrattan.wordpress.com/2007/09/03/preparing-powershell-for-sharepoint-and-moss-2007/) and then using this line:
ReplyDelete$spsite.Quota = $quotaTemplate
or for the bulk replace script:
$spsite.Quota = $newQuotaTemplate
although bear in mind that I haven't tested it yet for 2007...
Thank you for your help but it doesn't Work.
ReplyDeleteHere my Sscript if you've an idea. I'm a newbee in powershell but i try :)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
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
function AssignQuotaTemplate ($Name, $Url)
{
$SPsite=[Microsoft.Sharepoint.SPSite] ("http://testcollaboration.eu.areva.corp/test")
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$Name]
$SPsite.Quota = $quotaTemplate
}
Almost... Change the URL you have specified in your $SPSite declaration to the variable $Url. Then include the actual URL when running the AssignQuotaTemplate function - full script below
ReplyDelete[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
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
function AssignQuotaTemplate ($Name, $Url)
{
$SPsite = [Microsoft.Sharepoint.SPSite] ($Url)
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$Name]
$SPsite.Quota = $quotaTemplate
}
AssignQuotaTemplate -Name "Power" -Url "http://portal"
Thank you very much for your help. The Script works Well. The issue was the F5 Refresh not Work.
ReplyDeleteTo see the changed Quotatemlate, you need to go to other page and come back to the sitecollectionquota and locks from central admin page.
Hey this was a great help, i used bits of this in my auto deploy script http://autospdeploy.codeplex.com
ReplyDeleteI've tried however to use powershell to delete quotas and have run into problems. I tried the following but no luck:
Function DeleteQuota ($name)
{
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$name]
$contentService.QuotaTemplates.Delete($quotaTemplate)
$contentService.Update()
}
any thoughts?
James - Are you trying to remove a quota from a site collection or remove the quota template from the farm entirely?
ReplyDeleteHi Phil
ReplyDeleteCan you explain why you needed to change your code from this
function AssignQuotaTemplate ($Name, $Url)
{
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$Name]
Set-SPSite -Identity $Url -QuotaTemplate $quotaTemplate
}
To this for Nicolas stuff to work
function AssignQuotaTemplate ($Name, $Url)
{
$SPsite = [Microsoft.Sharepoint.SPSite] ($Url)
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$Name]
$SPsite.Quota = $quotaTemplate
}
I've done the same for myself and everything works like a charm. I'm just trying to understand why?
I'm also now trying to get the BulkLoad code to run, but am getting errors similar the what the above code gave before you amended it and posted back to Nicolas?
ReplyDeletefunction BulkReplaceQuotaTemplates ($WebApp, $OldTemplate, $NewTemplate)
{
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$oldQuotaTemplate = $contentService.QuotaTemplates[$OldTemplate]
$newQuotaTemplate = $contentService.QuotaTemplates[$NewTemplate]
$webApplication = Get-SPWebApplication $WebApp
$webApplication | Get-SPSite -limit all | ForEach-Object {
if ($_.Quota.QuotaID -eq $oldQuotaTemplate.QuotaID) {
Set-SPSite -Identity $_.Url -QuotaTemplate $newQuotaTemplate
}
}
}
The term 'Get-SPWebApplication' is not recognized as a cmdlet, function, operable program, or script file. Verify the t
erm and try again.
At C:\Users\120575b.syn\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:28 char:43
+ $webApplication = Get-SPWebApplication <<<< $WebApp
The term 'Get-SPSite' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and tr
y again.
At C:\Users\120575b.syn\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:29 char:33
+ $webApplication | Get-SPSite <<<< -limit all | ForEach-Object {
Is there some further amendments which need to be made? Any advice much appreciated!
Many thanks in advance
Steve
Hmmm, after some more digging, testing, learning! I'm still trying to figure out where I'm going wrong here, however I have some ideas (gradually I think I am fathoming this out!)
ReplyDeleteIs your last code snippet for the bulkquotatemplate only going to work with SP2010 because of the included PowerShell cmdlets?
The real question then, is could it ever work on SharePoint 2007?
VitalHostage - that's a lot of questions! :-)
ReplyDeleteYes, you are correct, SP2010 includes the Set-SPSite cmdlet, which isn't available in 2007. Neither do the Get-SPWebApplication or Get-SPSite cmdlets either.
Check this article for 2007 replacements to these cmdlets and see if you can work it out from there: http://get-spscripts.com/2011/03/using-powershell-scripts-with-wss-30.html
Hi Phil
ReplyDeleteThanks for the information. Much appreciated. Nothing like trying to reinvent the wheel to get that banging head against wall feeling!
I can work around the shortcomings of 2007, however I'm still slightly confused over one thing, however I'll figure that out for myself instead of asking you for an answer.
Cheers for getting back in touch though. Much appreciated
I wanted to thank you because your script saved me a lot of aggravation.
ReplyDeleteI needed to have these functions available in C#, so I created a module file in powershell with your functions, but adjusted to play well in powershell.
You can save the below as a .ps1 file and load it into normal powershell or sharepoint powershell. The parameters were adjusted to the v2 format and the functions were set to global.
Now you can do New-SPQuotaTemplate
Add-PSSnapin Microsoft.SharePoint.PowerShell -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
function global:New-SPQuotaTemplate
{
param(
[Parameter(Position=0, Mandatory=$true)]
[string]$Name,
[Parameter(Position=1, Mandatory=$true)]
[int]$MaxLevelMB,
[Parameter(Position=2, Mandatory=$true)]
[int]$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()
}
function global:Set-QuotaTemplate
{
param(
[Parameter(Position=0, Mandatory=$true)]
[string]$Name,
[Parameter(Position=1, Mandatory=$true)]
[string]$Url
)
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$Name]
Set-SPSite -Identity $Url -QuotaTemplate $quotaTemplate
}
function global:New-BulkReplaceQuotaTemplates
{
param(
[Parameter(Position=0, Mandatory=$true)]
[string]$WebApp,
[Parameter(Position=1, Mandatory=$true)]
[string]$OldTemplate,
[Parameter(Position=2, Mandatory=$true)]
[string]$NewTemplate
)
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$oldQuotaTemplate = $contentService.QuotaTemplates[$OldTemplate]
$newQuotaTemplate = $contentService.QuotaTemplates[$NewTemplate]
$webApplication = Get-SPWebApplication $WebApp
$webApplication | Get-SPSite -limit all | ForEach-Object {
if ($_.Quota.QuotaID -eq $oldQuotaTemplate.QuotaID) {
Set-SPSite -Identity $_.Url -QuotaTemplate $newQuotaTemplate
}
}
}
Just want to say thanks!!! Your code worked like a charm and saved me many hours of labor.
ReplyDelete2015-12-7 xiaozhengm
ReplyDeletefitflops clearance
michael kors uk
tory burch outlet
oakley sunglasses
nike outlet
louis vuitton outlet
louis vuitton pas cher
kate spade outlet
gucci outlet
coach outlet
michael kors outlet
canada goose uk
coach factory outlet
christian louboutin shoes
nike blazer
jordan 8s
michael kors handbags
jordan 3 infrared
caoch outlet
true religion outlet
air jordan uk
michael kors
longchamp outlet
adidas shoes uk
coach factory outlet
coach factory outlet
nike blazers
ugg australia
nike uk
coach factory outlet
tiffany and co
basketball shoes
michael kors outlet uk
louboutin
air jordans
chaussure louboutin
air jordan 13
ugg outlet
louis vuitton outlet
Great Article..
ReplyDeleteOnline DotNet Training
.Net Online Training
Dot Net Training in Chennai
IT Training in Chennai
20160301meiqing
ReplyDeletecanada goose jackets
michael kors online
abercrombie
kate spade handbags
coach factory outlet
louis vuitton outlet
louis vuitton outlet
oakley sunglasses
gucci bags
cheap oakleys
tory burch handbags
ray ban sunglasses outlet
louis vuitton
cheap uggs
nfl jerseys wholesale
longchamp outlet
coach factory
gucci shoes
toms shoes
ray ban sunglasses
canada goose jackets
christian louboutin
coach outlet
louis vuitton handbags
louis vuitton handbags
cheap oakley sunglasses
canada goose jackets
air jordan retro
the north face
lebron 12
louis vuitton
chaussure louboutin
ReplyDeleteair max 90 white
louis vuitton outlet online
yeezy boost 350 white
cheap jordan shoes
louis vuitton purse
skechers outlet
fitflops shoes
adidas pure boost black
louis vuitton bags
fitflops
true religion jeans
burberry outlet stores
discount oakley sunglasses
michael kors outlet
cheap ray bans
coach outlet online
louis vuitton outlet
ferragamo outlet
ray ban outlet store
michael kors outlet online
moncler uk
dolce and gabbana outlet online
pandora charms uk
nike store uk
ralph lauren uk
yeezy boost
michael kors handbags
reebok shoes
ed hardy
michael kors canada
louboutin pas cher
pandora jewelry outlet
cheap basketball shoes
longchamp handbags
20160721caiyan
christian louboutin sale
ReplyDeletecoach factory outlet
michael kors outlet
louis vuitton bags
louis vuitton outlet
toms
coach outlet store online
adidas shoes
ray ban sunglasses uk
oakley sunglasses
coach outlet
louis vuitton handbags
abercrombie kids
michael kors purses
coach outlet
coach outlet
louis vuitton outlet
michael kors purses
coach factory outlet
adidas uk
lebron james shoes 12
coach factory outlet
coach outlet online
louis vuitton handbags
ray ban sunglasses
celine
polo ralph lauren
kate spade outlet
michael kors handbags
michael kors
lebron james shoes
louis vuitton handbags
louis vuitton bags
christian louboutin outlet
cheap oakley sunglasses
mont blanc pens
adidas outlet store
nike nfl jerseys
ralph lauren outlet
beats headphones
20168.8wengdongdong
washington wizards jerseys
ReplyDeletelouis vuitton outlet
hollister clothing
louis vuitton outlet
christian louboutin uk
burberry handbags
nike tn pas cher
cincinnati bengals jerseys
christian louboutin
oakley sunglasses
20173.9chenjinyan
The Article is very interesting and I like it. Agen jual fiforlif Balikpapan , Harga Fiforlif di Balikpapan , Jual Fiforlif Murah di Balikpapan , Manfaat Fiforlif , Distributor Fiforlif di Balikpapan
ReplyDeleteThis information is very useful. thank you for sharing. and I will also share information about health through the website
ReplyDeleteCara Mengobati radang Usus
Cara Mengatasi Leher kaku
Cara Menghilangkan Benjolan di Bibir
Obat Nyeri haid
Cara Menghilangkan Keloid
Penyebab Benjolan di Leher
Pengobatan Meningioma Selain Operasi
birkin bags
ReplyDeletejordan 11 win like 96
cheap nfl jerseys
nmd r1
clarks shoes
cheap soccer cleats
fenty puma
pandora jewelry
curry shoes
nike factory
2018-0505y
There are those who want to collect vintage items like Michael Kors Factory Outlet with genuine and high quality leathers from Michael Kors. To be able to grab a quality Michael Kors Bags Outlet item of your choice, make sure to be very careful in selecting what to buy, how to buy and where to buy the Michael Kors Outlet Online.
ReplyDeleteThanks for sharing the information
ReplyDeleteKhasiat QnC Jelly Gamat
Obat Eksim Atopik
Pengobatan Herbal Penyakit Liver
Cara Mengobati Alergi Dingin
Obat Paling Mujarab untuk Diabetes
Obat Batu Empedu Alami
PENGOBATAN PENYAKIT AMANDEL
https://myserviceshome.com/cleaning-company-in-riyadh/
ReplyDeletehttps://myserviceshome.com/transfer-to-riyadh-is-cheap/
https://myserviceshome.com/integrated-home-services-in-riyadh/
https://myserviceshome.com/insulation-foam-in-riyadh/
https://myserviceshome.com/detection-of-water-leaks-in-dammam/
Very Nice Blog Updation Keep Updating !!
ReplyDeleteCara Mengobati Penyakit Gagal Ginjal
Obat Penyakit Insomnia Paling Ampuh Tanpa Efek Samping
Obat Herbal Paling Ampuh Untuk Mengobati Penyakit Hipotiroid
Cara Alami Untuk Mengobati Batuk Kronis
Cara Mengobati Penyakit Usus Buntu
Pengobatan Kelenjar Tiroid
Thanks for the information, this is very useful. Allow me to share a health article here, which gods are beneficial to us. Thank you :)
ReplyDeleteObat Usus Buntu Tanpa Operasi
Cara Menghilangkan Kelenjar Tiroid
Cara Mengatasi Sembelit atau Konstipasi
Obat Iritasi Mata Karena Softlens
Obat Kelenjar Getah Bening Menahun
Cara Penyembuhan Demam Tifoid/Tipes
Thank you for joining us. his article is very helpful
ReplyDeleteObat Herbal Paling Ampuh Untuk Mengobati Penyakit Hipotiroid
Manfaat Buah-Buahan Untuk Kesehatan
Obat Untuk Mengobati penyakit osteoarthritis
Bahaya Penyakit Muntaber dan cara mengatasinya
Obat Penyakit Jantung Bengkak
Cara Mengobati Penyakit Leukimia
Thank you for sharing an interesting and very useful article. And let me share an article about health here I believe this is useful. Thank you :)
ReplyDeleteObat Berengan/Sariawan/Luka di Sudut Bibir
Masker Wajah untuk Kulit Berminyak dan Berjerawat
Solusi Sehat Alami
Manfaat Buah Pisang Untuk Wajah
Jenis Pisang untuk Masker Wajah
Obat Sakit Pundak dan Leher
cheap nfl jerseys
ReplyDeletecheap jerseys
cheap jerseys from china
wholesale jerseys
cheap nfl jerseys from china
china jerseys
nfl jerseys china
wholesale nfl jerseys
cheap authentic nfl jerseys
cheap jerseys online
cheap authentic jerseys
cheap sports jerseys
cheap wholesale jerseys
china wholesale jerseys
discount nfl jerseys
cheap authentic jerseys from china
discount jerseys
custom cowboys jersey
nfl jerseys cheap
cheap nfl jerseys china
authentic nfl jerseys
كما نعلم أن الموكيت يتعرض لعدة حالات التلف وايضا للضرر وايضاًً الشوائب الخطيرة التي يتعرض لها موكيت وأيضاًً بعض السجاد وهذا عن طريق النوافذ أو نتيجة لـ النظافة التقليدية ، التي تؤثر سلبًا على الموكيت وتسبب تلف الألياف وايضاً التعرض لسقوط بقايا الغذاء ، التي تسقط على الموكيت .
ReplyDeleteشركة النجوم لخدمات التنظيف
شركة تنظيف شقق بالطائف
شركة تنظيف فلل بالطائف
شركة تنظيف مجالس بالطائف
สล็อตออนไลน์
ReplyDeleteโกลเด้นสล็อต
goldenslot
golden slot
Looking back at Bon Iver's 2008 album, For Emma, Forever Ago Ray Ban Round Sunglasses and comparing it to Coach Bags On Sale Online his latest effort, 22 A Million you can hear the artist's progression. Slow acoustic guitars, emotional rawness and Jordan Shoes For Sale Cheap soft vocals were left behind for electronics blips and reverb drenched falsettos. Despite the change in instrumentation Justin Vernon's sound has Coach Outlet Store Online never been more realized than on For Emma, Forever Ago a Real Yeezy Shoes lover letter to a series of lost lovers.
ReplyDeleteThey've got a drum team that sits up top and bangs
During the recent period, there has become a large spread of many private companies for cleaning, and we find that our company is the best at all, with the presence of many companies, our company has become a big role relative to what it has provided many wonderful and distinctive services to its customers, and it is worth noting that our company works daily
ReplyDeleteشركة تنظيف فلل بعنيزة
شركة تنظيف خزانات بعنيزة
شركة رش مبيدات بعنيزة
شركة تسليك مجاري بعنيزة
شركة عزل أسطح بعنيزة