Add/Update SP (SharePoint) Site Quota Template using PowerShell

Please see the reusable script:

$ver = $host | select version if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } function AddUpdate-SPQuotaTemplate{ <# .Synopsis This advanced function add/update Site Quota Template. .Description This function uses .NET code to instantiate an instance of an SPQuotaTemplate class. An instance of the SPWebService class is instantiated and the Quota Template is added/updated to the Quota Templates Collection. .Example C:\PS>AddUpdate-SPQuotaTemplate -AddTemplateName "Custom" -UpdateTemplateName "" -StorageMaximumLevel 2GB -StorageWarningLevel 1GB -UserCodeMaximiumLevel 100 -UserCodeWarningLevel 75 This example creates an SP Quota Template called Custom with a maximum size of 2GB and a warning size of 1GB. Sandboxed solutions are limited to 100, with a warning level of 75. .Example C:\PS>AddUpdate-SPQuotaTemplate -AddTemplateName "Custom" -UpdateTemplateName "" -StorageMaximumLevel 4GB -StorageWarningLevel 3GB This example creates an SP Quota Template called Custom with a maximum size of 4GB and a warning size of 3GB .Notes Name: AddUpdate-SPQuotaTemplate Author: Riyaz Sheriff Last Edit: 2/09/2015 Keywords: Quota Template, Quotas and Locks .Link #Requires -Version 2.0 #> [CmdletBinding()] Param( [Parameter(Mandatory=$true)][String]$AddTemplateName, [Parameter(Mandatory=$false)][String]$UpdateTemplateName, [Parameter(Mandatory=$true)][Int64]$StorageMaximumLevel, [Parameter(Mandatory=$true)][Int64]$StorageWarningLevel, [Parameter(Mandatory=$false)][System.Double]$UserCodeMaximumLevel, [Parameter(Mandatory=$false)][System.Double]$UserCodeWarningLevel ) # Instantiate an instance of an SPQuotaTemplate class # Write-Verbose "Instantiating an instance of an SPQuotaTemplate class" $contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService $quotaTemplate = $contentService.QuotaTemplates[$AddTemplateName]; # Got an Instance of the SPWebService Class # Write-Verbose "Got an instance of an SPWebService class" if($quotaTemplate -ne $null){ # Ensure before renaming $expectedNewTemplate = $contentService.QuotaTemplates[$UpdateTemplateName]; if($expectedNewTemplate -eq $null -and $UpdateTemplateName -ne ""){ # New name quota template is already found # Write-Verbose "A Quota template with the name $UpdateTemplateName does not exisit...." $quotaTemplate.Name = $UpdateTemplateName $quotaTemplate.StorageMaximumLevel = $StorageMaximumLevel $quotaTemplate.StorageWarningLevel = $StorageWarningLevel $quotaTemplate.UserCodeMaximumLevel = $UserCodeMaximumLevel $quotaTemplate.UserCodeWarningLevel = $UserCodeWarningLevel $contentService.Update() Write-Host "Quota Template $AddTemplateName was updated successfully" -foreground Green } else{ Write-Host "Template $UpdateTemplateName already exists, cannot rename...." -ForegroundColor Yellow } } else{ # Set the Properties # Write-Verbose "Setting properties on the Quota object" $newQuotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate $newQuotaTemplate.Name = $AddTemplateName $newQuotaTemplate.StorageMaximumLevel = $StorageMaximumLevel $newQuotaTemplate.StorageWarningLevel = $StorageWarningLevel $newQuotaTemplate.UserCodeMaximumLevel = $UserCodeMaximumLevel $newQuotaTemplate.UserCodeWarningLevel = $UserCodeWarningLevel # Get an Instance of the SPWebService Class # Write-Verbose "Getting an instance of an SPWebService class" $contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService $contentService.QuotaTemplates.Add($newQuotaTemplate) $contentService.Update() Write-Host "Quota Template $AddTemplateName added successfully" -foreground Green } } # Reconfigure if found, if not add a new one. AddUpdate-SPQuotaTemplate -AddTemplateName "Small Team Site (2GB)" ` -UpdateTemplateName "" ` -StorageMaximumLevel 2GB ` -StorageWarningLevel 1740MB ` -UserCodeMaximumLevel 300 ` -UserCodeWarningLevel 300 AddUpdate-SPQuotaTemplate -AddTemplateName "Medium Team Site (5GB)" ` -UpdateTemplateName "" ` -StorageMaximumLevel 5GB ` -StorageWarningLevel 4352MB ` -UserCodeMaximumLevel 300 ` -UserCodeWarningLevel 300 AddUpdate-SPQuotaTemplate -AddTemplateName "Large Team Site (10G)" ` -UpdateTemplateName "" ` -StorageMaximumLevel 10GB ` -StorageWarningLevel 8704MB ` -UserCodeMaximumLevel 300 ` -UserCodeWarningLevel 300

PowerShell: Set/Configure Document Library with MajorVersionLimit, MajorWithMinorVersionsLimit & require to checkout before editing

Just finished coding a PowerShell function to achieve the following:
Approval Library:
– Require content approval;
– Require items to be checked out;
– Require major versions and minor versions;
– Keep a maximum of 5 major versions and drafts for 1 major version.

Here is the PS function which I coded to satisfy the above design requirement:

function ConfiguringVersioningSettings($webUrl, $listName, $requireCheckOut, $majorVersionLimit, $minorVersionLimit){
       Write-Message "Configuring version settings for $listName..." "cyan"
       $web = Get-SPWeb $webUrl
       $library = $web.Lists[$listName]
       $library.EnableVersioning = $true
       $library.EnableMinorVersions = $true
       $library.MajorVersionLimit = $majorVersionLimit
       $library.MajorWithMinorVersionsLimit = $minorVersionLimit
       $library.ForceCheckOut = $requireCheckOut

Why do we restrict the number of versions?

Out of the box SharePoint keeps all versions in the document library. Once we enable the versioning on libraries all versions size is counted towards the site collection quota, there is no such thing as storing deltas in this case, they’re the full versions. I.e. each time we save the document, SharePoint stores as a separate copy of complete document in the database though we make a small change. Just imagine If we have a 100 MB document with 20 different versions (Around 2 GB of storage capacity). With large documents, even a small but active library can eat up your database in a hurry. If you have a limited site collection storage capacity, this is going to be a big issue to store more number of documents as database reaches it max storage capacity very soon. So, restrict at max 3 major and 3 minor versions at any point in time in the document library.

If you forget to set the limitation, there is no way from SharePoint out-of-the-box to house keep/manage specific versions from document version history. Either you have to remove/delete all versions or all minor versions

To enable version history on a document library choose the library you would like to set version settings.

Library Settings > in the settings page, under General Settings > click Versioning Settings:

– Check the checkbox “Create major and minor (draft) versions” option

– And, check the checkboxes to keep 3 major and 3 minor versions

Happy Point Sharing!

Outbound e-mail has not been configured.

Severity 1 – Error 
Category Configuration 
Explanation A default SMTP server has not been configured.  One or more web applications do not have SMTP servers configured.  Because of this, features such as alerts will not function properly.
Remedy Configure an outgoing e-mail server from the central administration site or execute the following command: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\bin\stsadm.exe-o email -outsmtpserver <SMTP server> -fromaddress <> -replytoaddress <> -codepage <codepage> For more information about this rule, see


Solution – PowerShell approach:

$ErrorActionPreference = "Stop"
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

$SMTPSvr = ‘mailserver.domainame.local’
$FromAddr = ‘noreply@domainame.local’
$ReplyAddr = ‘noreply@domainame.local’
$Charset = 65001

$CAWebApp = Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication }
$CAWebApp.UpdateMailSettings($SMTPSvr, $FromAddr, $ReplyAddr, $Charset)


Verify@:  Central Administration > System Settings > Configure outgoing e-mail settings