Add/Update SP (SharePoint) Site Quota Template using PowerShell

Please see the reusable script:

$ver = $host | select version if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } function AddUpdate-SPQuotaTemplate{ <# .Synopsis This advanced function add/update Site Quota Template. .Description This function uses .NET code to instantiate an instance of an SPQuotaTemplate class. An instance of the SPWebService class is instantiated and the Quota Template is added/updated to the Quota Templates Collection. .Example C:\PS>AddUpdate-SPQuotaTemplate -AddTemplateName "Custom" -UpdateTemplateName "" -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>AddUpdate-SPQuotaTemplate -AddTemplateName "Custom" -UpdateTemplateName "" -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: AddUpdate-SPQuotaTemplate Author: Riyaz Sheriff Last Edit: 2/09/2015 Keywords: Quota Template, Quotas and Locks .Link http://consultantpoint.wordpress.com #Requires -Version 2.0 #> [CmdletBinding()] Param( [Parameter(Mandatory=$true)][String]$AddTemplateName, [Parameter(Mandatory=$false)][String]$UpdateTemplateName, [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" $contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService $quotaTemplate = $contentService.QuotaTemplates[$AddTemplateName]; # Got an Instance of the SPWebService Class # Write-Verbose "Got an instance of an SPWebService class" if($quotaTemplate -ne $null){ # Ensure before renaming $expectedNewTemplate = $contentService.QuotaTemplates[$UpdateTemplateName]; if($expectedNewTemplate -eq $null -and $UpdateTemplateName -ne ""){ # New name quota template is already found # Write-Verbose "A Quota template with the name $UpdateTemplateName does not exisit...." $quotaTemplate.Name = $UpdateTemplateName $quotaTemplate.StorageMaximumLevel = $StorageMaximumLevel $quotaTemplate.StorageWarningLevel = $StorageWarningLevel $quotaTemplate.UserCodeMaximumLevel = $UserCodeMaximumLevel $quotaTemplate.UserCodeWarningLevel = $UserCodeWarningLevel $contentService.Update() Write-Host "Quota Template $AddTemplateName was updated successfully" -foreground Green } else{ Write-Host "Template $UpdateTemplateName already exists, cannot rename...." -ForegroundColor Yellow } } else{ # Set the Properties # Write-Verbose "Setting properties on the Quota object" $newQuotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate $newQuotaTemplate.Name = $AddTemplateName $newQuotaTemplate.StorageMaximumLevel = $StorageMaximumLevel $newQuotaTemplate.StorageWarningLevel = $StorageWarningLevel $newQuotaTemplate.UserCodeMaximumLevel = $UserCodeMaximumLevel $newQuotaTemplate.UserCodeWarningLevel = $UserCodeWarningLevel # Get an Instance of the SPWebService Class # Write-Verbose "Getting an instance of an SPWebService class" $contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService $contentService.QuotaTemplates.Add($newQuotaTemplate) $contentService.Update() Write-Host "Quota Template $AddTemplateName added successfully" -foreground Green } } # Reconfigure if found, if not add a new one. AddUpdate-SPQuotaTemplate -AddTemplateName "Small Team Site (2GB)" ` -UpdateTemplateName "" ` -StorageMaximumLevel 2GB ` -StorageWarningLevel 1740MB ` -UserCodeMaximumLevel 300 ` -UserCodeWarningLevel 300 AddUpdate-SPQuotaTemplate -AddTemplateName "Medium Team Site (5GB)" ` -UpdateTemplateName "" ` -StorageMaximumLevel 5GB ` -StorageWarningLevel 4352MB ` -UserCodeMaximumLevel 300 ` -UserCodeWarningLevel 300 AddUpdate-SPQuotaTemplate -AddTemplateName "Large Team Site (10G)" ` -UpdateTemplateName "" ` -StorageMaximumLevel 10GB ` -StorageWarningLevel 8704MB ` -UserCodeMaximumLevel 300 ` -UserCodeWarningLevel 300

Pre-Populating Folder(s) in Document Library with the Help of List Instance Definition

Scenario:

Today when I was working on a requirement, I had the need to create a customized picture library. To create this picture library the required List Schema, Definition, Instance Template, etc. were created.

Challenge:

One challenge I had at the end was, that this Library had to be pre-populated with a folder to store some control files.
Here is how it was resolved:

Note: I will not explain how the list definition and schema were created as there are several posts out there to help.

Solution:

In the List Instance definition (manifest file), you just have to add the line shown below (Module.. Path..):

   1:  <?xml version="1.0" encoding="utf-8" ?>
   2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   
   4:    <ListInstance FeatureId="327B763B-A5E7-4ac2-8458-B6570D362C0B"
   5:                 Id="WattsUpImagesLibrary"
   6:                 Title="$Resources:MyResource,ListInstance_WattsUpImages_DisplayName"
   7:                 Description="$Resources:MyResource,ListInstance_WattsUpImages_Description"
   8:                 Url="WattsUpImagesLibrary"
   9:                 TemplateType="3111" 
  10:                 OnQuickLaunch="FALSE" />
  11:    <!-- Adding a folder to the list instance-->
  12:    <Module Path="ControlFiles" Url="WattsUpImagesLibrary/ControlFiles" />
  13:  </Elements>

Please take a special note of the URL attribute, the value “WattsUpImagesLibrary” is the one used above as URL of the instance.

The output as a result of this:

image

IMPORTANT: To be able to create folder in Document Library, your list need to have the content reference of “0x0120” OR a custom one derived from it in the format of 0x0120 + 00 + <Guid>

Creating a Feature for the Site Actions Menu in SharePoint 2010

Overview

You can add a custom menu item to the default Site Actions menu in Microsoft Windows SharePoint Services by creating a Feature with a CustomAction element. In this way, you can add custom commands to the default SharePoint user interface. These commands are available to users as they move between pages on a SharePoint site. When you create a Site Actions menu item, you can configure it to redirect the user to any URL. For example, you can redirect the user to another Web site. You can also redirect users to a custom application page that allows them either to see a custom display of data, or to perform custom operations on the content within the current site.

Code It

  1. Create a new Project in VS 2010 and under SharePoint (left) select Empty Project.
  2. Now enter the url of your SharePoint site for debugging and select deploy as a farm solution.
  3. Now, once you have the project open, right click on the Feature folder and Add a new feature.
  4. SharePoint automatically adds a feature and names it as Feature1. You can however change the feature name to something like CustomActionFetaure.
  5. With this you will have a feature designer opened in front of you set the Title description and scope of the feature.
  6. Now right click on the Project and add a new Item. In the Add New Item dialog, select Empty Element to create a blank element file.
  7. Add the below Code to the element.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="viewSiteManager"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="1000"
    Rights="ViewListItems,ManageAlerts" Title="Manage Content and Structure" Description="Reorganize content and structure in this site collection.">
    <UrlAction Url="~site/_layouts/sitemanager.aspx"/>
    </CustomAction>
    </Elements>

  8. Build the Project. Open the feature.xml file and verify that if contains the reference to the element.xml file.
  9. Now Deploy the wsp and activate the feature in your site.

Read It

When you create a CustomAction element, you must add an inner UrlAction element that contains a Url attribute. When you redirect the user to an application page, such as SiteManager.aspx, you must consider whether you want the application page to run inside the context of the current site or the current site collection. In the following example, the dynamic token ~site is added to the beginning of the URL. When Windows SharePoint Services parses this CustomAction element and creates the menu item, it replaces ~site with the actual URL of the current site.

"~site/_layouts/sitemanager.aspx"

The key to security trimming your custom action is the Rights attribute. This attribute allows you to specify SharePoint permissions that the user must have for the action to be visible. This can be a comma delimited list. For example:

Rights="ViewListItems,ManageAlerts"

When more than one value is specified, the set of rights are treated with an AND. This means the user must have all of the specified rights for it to be visible. Here is a list of the valid Microsoft.SharePoint.SPBasePermissions you could use:

http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions

Also, When you create the element for a custom menu item in the Site Actions menu, you have the option to configure it so that it is shown only to users who have administrative permissions. Note in the following example the addition of a new attribute named RequireSiteAdministrator.

RequireSiteAdministrator="TRUE"

When you add the RequireSiteAdministrator attribute, Windows SharePoint Services does not show the menu item to users who do not have administrative permissions. For a CustomAction element in a Feature that is scoped at the site-collection level, the menu item appears only for the site collection owner or administrator. For a CustomAction element in a Feature that is scoped at the site level, the menu item appears only to those who have administrative permissions within the current site.

Finally

siteaction

Related Link: http://blogs.msdn.com/b/edhild/archive/2008/01/16/how-to-add-security-trimming-info-to-custom-actions-in-sharepoint.aspx