SharePoint Online: Create a Document Library or List with Modern Experience UI using PowerShell

The new list and library experience in SharePoint Online improve the user experience by providing many features such as navigation, fast response, mobile UI, easier to use, etc. You can switch between classic & new experiences anytime. Here is the PowerShell-CSOM script to create a document library in SharePoint Online with a new experience UI.

PowerShell Script to create a document library in new experience UI:

Are you looking for a way to create a document library with the new experience in SharePoint Online? If so, PowerShell can help you get the job done.

#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 = "https://crescent.sharepoint.com/Projects"
$UserName="[email protected]"
$Password ="Password goes here"
 
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

Try { 
    #Set up the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
    $Context.Credentials = $credentials

    #Create new document library
    $ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
    $ListInfo.Title = "Project Documents"
    $ListInfo.TemplateType = 101 #Document Library
    $List = $Context.Web.Lists.Add($ListInfo)
    
    #Set "New Experience" as list property
    $List.ListExperienceOptions = "NewExperience" #Or ClassicExperience
    $List.Update()
    $Context.ExecuteQuery()

    Write-host "New Document Library Created!" -ForegroundColor Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
} 

This creates a new library, “Project Documents” in the modern new experience UI.

sharepoint online new list experience

PnP PowerShell to Create a List or Document Library with New Experience

Use this PnP PowerShell to create a document library with the new experience in SharePoint Online:

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Projects"
$ListName = "Team Projects"
$ListTemplate ="DocumentLibrary"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Create a document library using pnp powershell
    $List = New-PnPList -Title $ListName -Template $ListTemplate -ErrorAction Stop

    #Set list experience
    Set-PnPList -Identity $List -ListExperience NewExperience

    Write-host "List '$ListName' Created Successfully!" -f Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

Use “GenericList” as the $ListTemplate for creating a new custom list in SharePoint Online.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *