$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile = ".\SetQuotaTemplatePatch-$LogTime.rtf"
# Add SharePoint PowerShell Snapin
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
Add-PSSnapin Microsoft.SharePoint.Powershell
}
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
#Deleting any .rtf files in the scriptbase location
$FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
if($FindRTFFile)
{
foreach($file in $FindRTFFile)
{
remove-item $file
}
}
start-transcript $logfile
[string]$url = Read-Host "Enter the site collection url: [e.g. http://server_name]"
[string]$template = Read-Host "Enter the quota template name that has to be used: [e.g. MyTemplate]"
try {
Write-host "Configuring site collection to use specified quota template ..."
$quotaTemplate = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.QuotaTemplates |
Where-Object {$_.Name -eq $template}
Set-SPSite -Identity $url -QuotaTemplate $quotaTemplate
}
catch [Exception] {
Write-Error $Error[0]
$err = $_.Exception
while ( $err.InnerException ) {
$err = $err.InnerException
Write-Output $err.Message
}
}This code describe PowerShell script to set quota template to a SharePoint site collection.
