Get SharePoint Site Quota Templates using PowerShell


A week or two ago I posted a function that allows you to create new SharePoint Site Collection Quota Templates using PowerShell. In that post I mentioned that two more functions (Get, Remove) would be coming soon.

Today I am sharing the function which allows you to get SharePoint Quota Templates. Again, this code is almost verbatim taken from the book by Gary and Shannon, but I have added comment-based-help and put it into an advanced function with CmdletBinding attributes.

The code is pretty simple, and again if you want a detailed walk through – I strongly encourage you to check out Gary and Shannon’s book!

Without further ado, here is the function which I have called Get-SPQuotaTemplate. I’m also finishing up the third function, Remove-SPQuotaTemplate – look for that post very soon!

Simply dot-source the function and then run it like a standard Windows PowerShell Cmdlet.

function Get-SPQuotaTemplate {
<#
.Synopsis
 This advanced function retrieves a SharePoint Site Quota Template.
.Description
 This function uses .NET code to retrieve the Quota Templates collection
 using a Microsoft.SharePoint.Administration.SPWebService object.
.Example
 C:\PS>Get-SPQuotaTemplate -Name "Custom"

 This example retrieves a SharePoint Quota Template called Custom in the
 current farm.
.Example
 C:\PS>Get-SPQuotaTemplate

 This example retrieves all SharePoint Quota Templates in the current farm.
.Notes
 Name: Get-SPQuotaTemplate
 Author: Ryan Dennis
 Last Edit: 5/10/2012
 Keywords: Quota Template, Quotas and Locks
.Link
 http://www.sharepointryan.com
 http://twitter.com/SharePointRyan
#Requires -Version 2.0
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false)][String]$Name
)
$Templates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.QuotaTemplates
 if ($Name)
 {
 $Templates | Where-Object {$_.Name -eq $Name}
 }
 else
 {
 $Templates
 }
}

Advertisement

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s