Quota Templates and Powershell
Quota Templates and Powershell
Continuing the series using Powershell and Microsoft SharePoint Products and Technologies, this weeks script sample illustrates how Powershell can be leveraged to programmatically provision Quota Templates in Windows SharePoint Services 3.0 and/or Microsoft Office SharePoint Server 2007.
Instructions
- Copy the source below into somefile.ps1.
- Copy the Xml source in QuotaTemplates.xml.
- In the Windows Powershell console call ./somefile.ps1
Source
#——————————————————————————-
# Function: main
# Description: Main entry point for the script. Loads the configuration source
# Xml and initializes the foreach loop to iterate over a
# collection of Xml nodes.
# Parameters: None
#——————————————————————————-
function main()
{
[xml]$cfg = Get-Content .QuotaTemplates.xml
if( $? -eq $false ) {
Write-Host “Cannot load configuration source Xml $cfg.”
return $false
}
$cfg.Configuration.QuotaTemplates.QuotaTemplate | ForEach-Object {
new-QuotaTemplates( $_ )
}
}
#——————————————————————————-
# Function: new-QuotaTemplates
# Description: This script enables you to do programmatically what you can do
# manually through the user interface in the SharePoint Site
# Management section on the Central Administration Quota
# Templates page.
# Parameters: None
#——————————————————————————-
function New-QuotaTemplates( [object] $cfg )
{
[Void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Sharepoint”)
$webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quota=New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
$quota.Name = $cfg.Name
$quota.StorageMaximumLevel = $cfg.StorageMaximumLevel
$quota.StorageWarningLevel = $cfg.StorageWarningLevel
$webService.QuotaTemplates.Add($quota);
$webService.Update();
}
main
Source Xml