Create document library sharepoint online powershell

Create List or Library in SPO PowerShell
InfoPath alternatives for form designing SharePoint

In this article we will discuss how we can create list or document library using PowerShell in SharePoint online.

PowerShell Script to create list/document library in SharePoint online:

Below is the powershell script which can be used to create list or document library in SharePoint online.

function CreateSPOList {
    #All the pre required variable to connect SPO.
    $strSiteURL = “<< Site URL >>”
    $strUsrName = “<< Site User ID >>”
    $strLstTitle = “Loan Details”
    $strLstDesc = “Various loan details in bank!!!”
    $strLstTempID = 101
    #Reading Password from end user
    $strPWD = Read-Host “Please enter the password for $($strUsrName)” -AsSecureString
    #Creating object to SPO with the provided user name and password
    $ObjSPOCredls = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($strUsrName, $strPWD)
    # Creating client context object with the provided user name and password
    $ObjContext = New-Object Microsoft.SharePoint.Client.ClientContext($strSiteURL)
    $ObjContext.credentials = $ObjSPOCredls
    #create loan details list with the list template ID 101 (document library template)
    $ObjLstLoanDet = New-Object Microsoft.SharePoint.Client.ListCreationInformation
    $ObjLstLoanDet.title = $strLstTitle
    $ObjLstLoanDet.description = $strLstDesc
    $ObjLstLoanDet.TemplateType = $strLstTempID
    $ObjLst = $ObjContext.web.lists.add($ObjLstLoanDet)
    $ObjContext.load($ObjLst)
    # Sending request to SPO with all the pre loaded information.
    try{
        $ObjContext.executeQuery()
        write-host “Successfully Creates List $($strLstTitle)” -foregroundcolor green
    }
    catch{
        write-host “Error :: $($_.Exception.Message)” -foregroundcolor red
    }
}
CreateSPOList



How to execute the script:
– Open SharePoint online command let as administrator
– Execute the script to create the list

Once you execute the script, you can see the output for PowerShell.

Create List or Library in SPO PowerShell Tutorial
Create List or Library in SPO PowerShell Tutorial

After this the document library will be created and the output will be as follows:

Create List or Library in SPO PowerShell
Create List or Library in SPO PowerShell

Hope this helps, enjoy development in SharePoint online !!!

Similar SharePoint 2013 Tutorials

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 12 years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019

View all posts by Krishna Vandanapu →

Leave a Reply