Share via


CSOM SharePoint Online Create List Using PowerShell

CSOM SharePoint Online Create List Using PowerShell

Summary

In this Wiki let's explore PowerShell code for creating List in SharePoint Online

Help

help about_Methods -Detailed
help about_Variables -Detailed
help Read-Host -Parameter AssecureString
help Add-Type -Detailed
help Import-Module -Detailed

PowerShell Code

#Import the required DLL
Import-Module 'C:\Temp\CSOM\Microsoft.SharePoint.Client.dll'
Import-Module 'C:\Temp\CSOM\Microsoft.SharePoint.Client.Runtime.dll'
$site = 'https://Chensoffice365.sharepoint.com/'
$admin = 'Chendrayan@Chensoffice365.OnMicrosoft.Com'
$password = Read-Host 'Enter Password' -AsSecureString
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials

$site = $context.Web
$context.Load($site)
$context.ExecuteQuery()

#Create List
$listinfo =New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listinfo.Title = 'CSOM List'
$listinfo.TemplateType = [Microsoft.SharePoint.Client.ListTemplateType]'GenericList'
$list = $web.Lists.Add($listinfo)
$context.ExecuteQuery()


Write-Host "Successfully Created List $($listinfo.Title)"

Explanation