Thursday, December 4, 2014

SharePoint Online: PowerShell to Create a List

Requirement: Create list in SharePoint online using PowerShell

SharePoint online PowerShell create list:
Here is how to create a list in sharepoint online using PowerShell

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteURL = ""
$ListName="Parent Project"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
    #Get All Lists 
    $Lists = $Ctx.Web.Lists

    #Check if List doesn't exists already
    if(!($Lists.Title -contains $ListName))
        #sharepoint online powershell create list
        $ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
        $ListInfo.Title = $ListName
        $ListInfo.TemplateType = 100 #Custom List
        $List = $Context.Web.Lists.Add($ListInfo)
        $List.Description = "Repository to store project artifacts"
        write-host  -f Green "New List has been created!" 
        Write-Host -f Yellow "List '$ListName' already exists!" 
Catch {
    write-host -f Red "Error Creating List!" $_.Exception.Message

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. E.g.
$ListInfo.TemplateType = "107" #Task List

create list in sharepoint online using powershell
Related Post: Create document library in sharepoint online with PowerShell

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...