Create Asset Library in SharePoint 2010 using Powershell

Steps Involved:

 

1.       Create the input xml file which contains the inputs for creating Asset Library.

2.       Create ps1 file which contains the script for creating Asset Library.


CreateAssetLibrary.xml:


<?xml version="1.0" encoding="utf-8"?>

<CreateAssetLibrary>

  <SiteURL>http://serverName</SiteURL>

  <ListName>Digital Asset Library</ListName>

  <Description>Digital Asset Library</Description>

</CreateAssetLibrary>

 

 

 

CreateAssetLibrary.ps1:

 

## -------------------------------------------------------------------

## Master Powershell script for creating Asset Library

## Note:- Need to update the XML file path before running the script.

## Author   :

## Date           : 31-Oct-2011

## -------------------------------------------------------------------

 

#----------------Get the xml file---------------------------------------------------------------

 

[xml]$xmlData=Get-Content "D:\Vijai\POCScripts\CreateAssetLibrary.xml" 

$siteURL=$xmlData.CreateAssetLibrary.SiteURL

$listName=$xmlData.CreateAssetLibrary.ListName

$description=$xmlData.CreateAllContentScopeRule.Description

 

 

#----------------Create Asset Library------------------------------------------------------------

 

Function CreateAssetLibrary()

{    

      $oWeb=Get-SPWeb $siteURL

      if($oWeb.Lists.TryGetList($listName) -eq $null)

      {

            Write-Host -ForegroundColor Magenta "Creating" $listName " ........................."

            $oTemplate=$oWeb.ListTemplates["Asset Library"]

            $oWeb.Lists.Add($listName,$description,$oTemplate)

            Write-Host -ForegroundColor Green $listName " is created successfully."

      }

      else

      {

        Write-Host -ForegroundColor Yellow $listName " already exists."

      }

}

 

#----------------Calling the function------------------------------------------------------------

CreateAssetLibrary

Run the Script:

 

1.       Go to Start.

2.       Click on All Programs.

3.       Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell (run as Administrator).

4.       Run the D:\Vijai\POCScripts\CreateAssetLibrary.ps1