Get SharePoint Site Quota Templates using PowerShell
Posted by Ryan Dennis in Administration, PowerShell, PowerShell Cmdlets, PowerShell Function, PowerShell Script, Quota Templates, SharePoint 2010, WIndows Server 2008 on May 10, 2012
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
}
}
Create SharePoint Site Quota Templates using PowerShell
Posted by Ryan Dennis in Administration, PowerShell, PowerShell Cmdlets, PowerShell Function, PowerShell Script, Quota Templates, SharePoint 2010, WIndows Server 2008 on April 30, 2012
Last week I was stumbling through a site provisioning script, when I realized I was missing something that I needed – the ability to create a custom quota template and then apply it to a site collection. After doing some quick Get-Command work to try and find the out-of-the-box PowerShell Cmdlets, I quickly realized there are no OOTB Cmdlets to do this.
I was a little frustrated that this didn’t’ exist, but of course when I come across gaps in the OOTB PowerShell support for Microsoft SharePoint 2010 – I immediately look at that as an opportunity to not only figure out the problem, but to share the solution. Luckily for me, as I’ve done a few times now – I came across the solution in Gary Lapointe and Shannon Bray’s book. While they didn’t have a function, they did detail the essentials on how to create the objects necessary to provision quota templates.
After spending a little time this weekend putting it all together, I’m left with a pretty decent function that allows you to create site quota templates easily using PowerShell!
I have added comment-based help to this function, as my intention was to make it as reusable and thorough as possible. The code is pretty simple, and 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 New-SPQuotaTemplate. I’m also finishing up two other functions, Get-SPQuotaTemplate and Remove-SPQuotaTemplate – look for those soon!
Simply dot-source the function and then run it like a standard Windows PowerShell Cmdlet.
function New-SPQuotaTemplate {
<#
.Synopsis
This advanced function creates a new Site Quota Template.
.Description
This function uses .NET code to instantiate an instance of an
SPQuotaTemplate class. Once the object is created, an instance of the
SPWebService class is instantiated and the Quota Template is added to the
Quota Templates Collection.
.Example
C:\PS>New-SPQuotaTemplate -Name "Custom" -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>New-SPQuotaTemplate -Name "Custom" -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: New-SPQuotaTemplate
Author: Ryan Dennis
Last Edit: 4/27/2012
Keywords: Quota Template, Quotas and Locks
.Link
http://www.sharepointryan.com
http://twitter.com/SharePointRyan
#Requires -Version 2.0
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][String]$Name,
[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"
$Quota = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
# Set the Properties #
Write-Verbose "Setting properties on the Quota object"
$Quota.Name = $Name
$Quota.StorageMaximumLevel = $StorageMaximumLevel
$Quota.StorageWarningLevel = $StorageWarningLevel
$Quota.UserCodeMaximumLevel = $UserCodeMaximumLevel
$Quota.UserCodeWarningLevel = $UserCodeWarningLevel
# Get an Instance of the SPWebService Class #
Write-Verbose "Getting an instance of an SPWebService class"
$Service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
# Use the Add() method to add the quota template to the collection #
Write-Verbose "Adding the $($Name) Quota Template to the Quota Templates Collection"
$Service.QuotaTemplates.Add($Quota)
# Call the Update() method to commit the changes #
$Service.Update()
}
I’m now a Microsoft Virtual Technology Specialist (vTSP) in SharePoint!
Posted by Ryan Dennis in sharepoint, SharePoint 2007, SharePoint 2010, vTSP on April 17, 2012
It’s official, I’ve been nominated and accepted by Microsoft as a Virtual Technology Specialist (vTSP) in SharePoint! I’m extremely excited to be considered among the elite in the Microsoft Partner Community, and I look forward to learning more about the program and helping businesses find value using Microsoft SharePoint.
One of the first questions I had during this process was “What is a VTS?”
I’ve located this text, which explains the VTS Program:
The Microsoft Virtual Technology Specialist Program (VTSP) is a select group chosen from the elite in Microsoft’s partner community, whose focus is to augment Microsoft’s internal Technology Specialist team. Their primary role is to communicate the value of Microsoft Solutions to customers and to provide architectural guidance for Enterprise Integration solutions. The Microsoft VTSP program was designed to create a deeper relationship with Microsoft Partners, the Product Teams at Microsoft Corporate, and Regional Microsoft Offices, in order to provide highly skilled solution specialists to Microsoft customers. It is designed to enable a high performance team of partner-based resources to deliver pre-sale activities and resources to empower customers and help them meet their solution and integration needs.
Great, so now we know what the VTS program is about, but what’s also really cool is I now get access to information on the Microsoft corporate network such as knowledge bases, technical articles, training materials, and other resources. I also get guest access to Microsoft facilities, and priority for participating in Microsoft marketing events.
Overall this is a great opportunity for me as well as for ICC, who now has 3 Virtual Technology Specialists in the SharePoint Practice. I’m proud to be a part of this elite community, and I look forward to all that comes from it.
Ryan
