How to Create a SharePoint Document library Online using Powershell?

Hello Sharepointers,

Below is the sharepoint code to create a SharePoint doucment library in Sharepoint online/Office 365 environment using Powershell.

$siteURL = “https://mysite.sharepoint.com/sites/
$userName = “admin@mysite.onmicrosoft.com”
$listTitle = “My Custom Documents”
$listTemplate = 101
$password = Read-Host ” password for $($userName)” -AsSecureString
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$context.credentials = $SPOCredentials
$lName = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$lName.title = $listTitle
$lName.description = $listDescription
$lName.TemplateType = $listTemplate
$list = $context.web.lists.add($lName)
$context.load($list)
$context.executeQuery()
write-host ” Created $($listTitle)” -foregroundcolor green
Happy SharePointing !!

Leave a Reply

Your email address will not be published.