PowerShell script to create a SharePoint quota template, edit the highlighted are in yellow to set the maximum and minimum storage limit for the quota template.
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\CreateQuotaTemplatesPatch-$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
-
- $name = ""
- $storageMaximumLevel =""
- $storageWarningLevel =""
-
- [String]$name = Read-Host "Enter the new quota Template Name: [e.g. Custom]"
- [int64]$storageMaximumLevel = 10GB
- [int64]$storageWarningLevel = 9GB
-
- try {
-
- Write-host "Instantiating an instance of an SPQuotaTemplate class"
- $quota = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
- Write-host "Setting properties on the Quota object"
- $quota.Name = $name
- $quota.StorageMaximumLevel = $storageMaximumLevel
- $quota.StorageWarningLevel = $storageWarningLevel
- Write-host "Getting an instance of an SPWebService class"
- $service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
- Write-host "Adding the $($Name) Quota Template to the Quota Templates Collection"
- $service.QuotaTemplates.Add($quota)
- $service.Update()
- }
- catch [Exception] {
- Write-Error $Error[0]
- $err = $_.Exception
- while ( $err.InnerException ) {
- $err = $err.InnerException
- Write-Output $err.Message
- }
- }