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

Mapping an image to use within SharePoint

Scenario:

PWCSTeamSite module has an image file called “TeamSite.gif”, which I would like to use as:

http://pwcs.com.au/_layouts/15/images/PWCSTeamSite/TeamSite.gif

 

so ensure the following settings:

image

 

Physical file location on server:

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES\PWCSTeamSite

[   ] – {SharePointRoot}

[   ] – Template File

[   ] – Images\PWCSTeamSite

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