How to set list experience in SharePoint Online using PowerShell

 Office 365, SharePoint Online, Raghuramji
Jan 15 2017

In this blog, we shall check how to set the experience type set for document libraries/lists in site collection using PowerShell. This script requires SharePoint Online PnP module, install it from here.

function Get-ListExperience
{
    Param(
    [System.Management.Automation.PSCredential]$cred,
    [String]$Sitecollection    
         )
   Connect-PnPOnline -Url $Sitecollection -Credentials $cred
   $Alldoc = @()
   $Lists=Get-PnPList |Where-Object {$_.BaseTemplate -eq '101' -and $_.Title -ne 'Form Templates' -and $_.Title -ne 'Site Assets' -and $_.Title -ne 'Style Library'} 
   foreach($List in $Lists)
    {
        $DocList = "" | Select "Title","Url","ListExperienceOptions"
        $DocList.Title =$List.Title
        $DocList.Url =($List.DefaultViewUrl -split "/Forms/AllItems.aspx")[0]
        $DocList.ListExperienceOptions =$List.ListExperienceOptions
        $Alldoc+= $DocList
        $DocList =$null
     
    }
   
    $subwebs=Get-PnPSubWebs -Recurse
    foreach($subweb in $subwebs)
    {        
        Connect-PnPOnline -Url $subweb.Url -Credentials $cred        
        $Lists= Get-PnPList |Where-Object {$_.BaseTemplate -eq '101' -and $_.Title -ne 'Form Templates' -and $_.Title -ne 'Site Assets' -and $_.Title -ne 'Style Library'} 
        foreach($List in $Lists)
        {
            $DocList = "" | Select "Title","Url","ListExperienceOptions"
            $DocList.Title =$List.Title
            $DocList.Url =($List.DefaultViewUrl -split "/Forms/AllItems.aspx")[0]
            $DocList.ListExperienceOptions =$List.ListExperienceOptions
            $Alldoc+=$DocList
            $DocList=$null
        }    
    } 
    $Alldoc
}
$Sitecollection = Read-Host -prompt "Enter the Site Collection URL: "
$cred=Get-Credential 
Get-ListExperience -cred $cred -Sitecollection $Sitecollection