This PowerShell SharePoint tutorial explains, how to create a 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 a 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
To execute the PowerShell script follow the below steps:
Open SharePoint Online command let as administrator.
Execute the script to create the SharePoint list
Once you execute the script, you can see the output for PowerShell.
After this, the document library will be created and the output will be as follows:
You may like following PowerShell SharePoint tutorials:
- How to disable/enable alert for a list or library in SharePoint 2019/2016/2013
- How to activate publishing feature in SharePoint 2013/2016 using PowerShell Script
- 25+ PowerShell SharePoint Examples
- Getting Started with PnP PowerShell – SharePoint 2013/2016/SharePoint Online
- Delete Hidden Web Application in SharePoint 2013 using PowerShell
- Change content type recursively using PowerShell SharePoint 2013
- Show hidden features in SharePoint 2013 using PowerShell
- Working with file modification time and date using PowerShell
- Steps to add items from CSV file to SharePoint Online List using PowerShell in CSOM
I hope this PowerShell script helps to create a SharePoint list or document library using PowerShell in SharePoint Online.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ 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
[…] Create document library sharepoint online PowerShell […]
[…] Create document library sharepoint online PowerShell […]