Create SharePoint List/Library Using PowerShell

Create SharePoint List/Library Using PowerShell


Use CreateSharePointLibrary function to create a new SharePoint List or Library.

Parameters : 
  1. $webUrl - Mandatory - SharePoint Web Url - e.g. http://server:port/ 
  2. $LibraryName - Mandatory - SharePoint Library Name 
  3. $Discription - Mandatory - SharePoint Library Description 
  4. $LibraryTemplate - Mandatory - SharePoint Library Template 



function CreateSharePointLibrary
{  
    [CmdletBinding()]
    Param(
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [string]$webUrl,
    [Parameter(Mandatory=$true)]
    [string]$LibraryName,
    [Parameter(Mandatory=$true)]
    [string]$Discription,
    [Parameter(Mandatory=$false)]
    [string]$LibraryTemplate
    )
   Start-SPAssignment -Global 

   $spWeb = Get-SPWeb -Identity $webUrl    
   $spListCollection = $spWeb.Lists  
   $spLibrary=$spWeb.Lists.TryGetList($LibraryName)
    if($spLibrary -ne $null)
    {
        write-host -f yellow "Library $LibraryName already exists in the site"
    }
    else
    {       
        Write-Host -NoNewLine -f yellow "Creating  Library - $LibraryName"
        $spListCollection.Add($LibraryName, $Discription, $LibraryTemplate)
        $spLibrary = $spWeb.GetList("$LibraryName")
        write-host -f Green "...Success!"
    }         
    Stop-SPAssignment -Global  
}


Function  Calling

$webUrl = "http://sever:port"

#-----------Document Library------------
$DocLibName = "DocLib1"
$LibraryTemplateDL = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
CreateSharePointLibrary $webUrl  $DocLibName  $DocLibName  $LibraryTemplateDL

# -------Data Connection Library-----------
$DataConnLibName = "DataConnLib1"
$LibraryTemplateDCL = [Microsoft.SharePoint.SPListTemplateType]::DataConnectionLibrary
CreateSharePointLibrary $webUrl  $DataConnLibName  $DataConnLibName $LibraryTemplateDCL


Similarly you can create any type of SharePoint List or Libraries , here are the details of List/Library Templates -
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx
Leave a Comment
  • Please add 1 and 8 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 1. Comment: Removed extra space in tag "SharePoint  2010", removed dash in tag "Power-Shell", added language tag and "Has Code"

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Richard Mueller edited Revision 1. Comment: Removed extra space in tag "SharePoint  2010", removed dash in tag "Power-Shell", added language tag and "Has Code"

Page 1 of 1 (1 items)