Thursday, December 4, 2014

SharePoint Online: PowerShell to Create a List or Document Library

Here is my CSOM PowerShell scripts to create new list and document libraries in SharePoint online.

SharePoint online: PowerShell script to Create Document Library:

#Load SharePoint CSOM Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null

#Variables for Processing
$SiteURL = ""
$LoginName =""
$LoginPassword ="Password" 

#Get the Client Context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

#supply Login Credentials
$SecurePWD = ConvertTo-SecureString $LoginPassword –asplaintext –force  
$Credential = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($LoginName,$SecurePWD)
$Context.Credentials = $Credential

#Create new document library
$ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListInfo.Title = "Project Docs"
$ListInfo.TemplateType = 101 #Document Library
$List = $Context.Web.Lists.Add($ListInfo)
$List.Description = "Repository to store project artifacts"

write-host "New Document Library has been created!"

PowerShell to Create list in SharePoint Online:
To create new list using Client side object model and PowerShell in SharePoint online, just change the TemplateType property value to 100 and run the above code.
$ListInfo.TemplateType = "100" #Custom List

SharePoint Online: PowerShell to Create a List or Document Library

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...