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 http://consultantpoint.wordpress.com #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

Setting up Document Expiration and Retention Policies for Libraries in SharePoint 2010

The following could be useful for someone who is trying to setup a Document Expiration and Retention Policies for a library in SharePoint 2010:

Check List:

1. Central Administrator should have retention enabled for sites created:

Central Administration > Security > Information policy > Configure Information Management Policy > Retention [Available for use in new site and list policies]

2. “Information Management Policy” and “Expiration Policy” are the two timer jobs which are responsible for retention policy. By default both will work “Weekly”, change this to suite your need.

Note: Set the recurring schedule in such a way that “Information Management Policy” job should run before the “Expiration Policy”.

[For testing purposes, you can either execute “Run Now” or set a shorter interval like every 5 minutes]

Steps to configure an Expiration Policy as below:

1. [Designated Document Library] > Document Library Settings > Information management policy settings >

a. Library and Folders (Change source or configure library schedule) > [Select Library and Folders].

b. Add a retention stage… > “This stage is based off a date property of the item Time Period :” Created + e.g. 0 days (for immediate action) > Action [Select Move to Recycle Bin]

c. Press OK/Apply to save the changes.

2. Add a document to the [Designated Document Library] and wait for the “Expiration Policy” timer job to execute.

That’s it; you should see that the item has been moved to the recycle bin.

Setting Expiration Dates

In SharePoint 2010, you have the option to set an expiration time based on any date property available in the drop-down list shown in Figure 8-5, including when it was declared a record. You can specify values between 0 to 500 years, 0 to 6000 months, or 0 to 182,500 days from the date selected from the drop-down list. In reality, all three settings have the same maximum amount of time, so your choice of which to select is really based on how precise you want the date setting to be. Selecting days will give you a more precise setting than months, and months will be more precise than years. The precision of the retention period required by your organization should be determined by your legal team.

Related references:

Retention Policy for document library in SharePoint 2010

http://weblogs.asp.net/sreejukg/archive/2010/11/11/retention-policy-for-document-library-in-sharepoint-2010.aspx

Creating a retention policy to start a workflow in SharePoint 2010 using PowerShell

http://get-spscripts.com/2011/08/creating-retention-policy-to-start.html

Bulk provisioning SharePoint 2010 document retention policies using PowerShell:

http://www.sharemuch.com/2011/04/11/bulk-provisioning-sharepoint-2010-document-retention-policies-using-powershell/

Add a workflow to a SharePoint list in all sites of a site collection using PowerShell

http://get-spscripts.com/2010/08/add-workflow-to-sharepoint-list-in-all.html

PowerShell – Automating the creation of sub sites for a given site collection

Add-PsSnapin Microsoft.SharePoint.PowerShell

# Loading of SharePoint dll.
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

# This script creates 50 subsites on the set site collection url.
Write-Output " "
Write-Output "Creation of 50 sub-sites in progress..."

# Parameters used in the script
$SiteCollectionUrl = "http://www.yukoon.com:81/department/dep1"
$SiteCollectionTemplate = "STS#0" 
$SiteCollectionLanguage = 1033
$StaplingWeb = "project_no_"

for($i=0 ; $i -lt 50 ; $i++)
{
      $siteId = $i + 1
    $SiteUrl = $SiteCollectionUrl + "/"
    $SubSiteName = $StaplingWeb + $siteId
    $SiteUrl = $SiteUrl += $SubSiteName

    Write-Host "Creating Sub-Site -- " $SubSiteName
    New-SPWeb $SiteUrl -Template $SiteCollectionTemplate -Name $SubSiteName  -UseParentTopNav -Language $SiteCollectionLanguage
    Write-Host "Site -> " $SubSiteName " successfully created."
}

Remove-PsSnapin Microsoft.SharePoint.PowerShell