Quota Templates and Powershell
Bill Baer ('bɛər) > Posts > Quota Templates and Powershell
| Code Samples Windows PowershellContinuing 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
| Bill Baer |
More like this...
- Using a Flic Smart Button as a PowerPoint Remote
- FileChecker Migration Assessment Sample Available for SharePoint Online and OneDrive for Business
- Quick Starting Demos and Windows PowerShell
- Yammer Redirection in SharePoint Server 2013 Service Pack 1
- Code Samples, Simple Translation using CSOM, REST, and Machine Translation Services