Create a Document Library in SharePoint using PowerShell

Requirement: Create a document library in SharePoint 2013 / 2016 using PowerShell.

PowerShell Script to Create New Document Library in SharePoint:

Are you looking for a way to create a document library in SharePoint using PowerShell? In this post, I’ll show you how to use PowerShell to create a new document library in SharePoint. This can be useful for automating the process of creating document libraries.

Here is how to create a document library in SharePoint 2013 using PowerShell:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#PowerShell Function to Create a Document Library in SharePoint 
Function Create-DocumentLibrary
{
 Param
 ( 
  [Microsoft.SharePoint.SPWeb]$Web,
  [String] $LibraryName,
  [String] $Description
 )
    #Get the Document Library template
    $ListTemplate = [Microsoft.Sharepoint.SPListTemplateType]::DocumentLibrary
  
    #Check if the library already exists
    if(($web.Lists.TryGetList($LibraryName)) -eq $null)
    {
        #Create the Library
        $Web.Lists.Add($LibraryName,$Description,$ListTemplate) > Null
   
        #Set Properties of Library such as OnQuickLaunch, etc
        $Library =  $Web.Lists[$LibraryName] 
        $Library.OnQuickLaunch = $true
        $Library.Update()
   
        Write-Host "Document library created successfully!" -f Green
    }
    else
    {
        Write-Host "Document Library '$LibraryName' already exists!" -f Red
    }
}
 
#Get the Web
$web = Get-SPWeb "https://intranet.crescent.com/"
 
#Call the function to create a library
Create-DocumentLibrary $web "Team Documents" "Library to Share Team Documents" 

This PowerShell script creates a document library in SharePoint 2013.

sharepoint powershell create new document library

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

4 thoughts on “Create a Document Library in SharePoint using PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *