1 min to read
How to set list experience in SharePoint Online using PowerShell
 
            
            
            
            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.
``` {.black .top-margin .bottom-margin}
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 
```
