#This script uses PnPPowerShell commands, hence ensure you have already installed #SharePointPnPPowerShellOnline
#Import module
#Import-Module SharePointPnPPowerShellOnline -ErrorAction "stop"
#Specify tenant admin and site URL, credentials
$OlUser = "adminaccountemail@domain.com"
$OlPassword = "password"
$securePassword = ConvertTo-SecureString $OlPassword -AsPlainText -Force
$OlSiteURL = "https://Online site url"
#Bind to site collection
$OlCreds = new-object -typename System.Management.Automation.PSCredential -argumentlist $OlUser, $securePassword
$SPOnlineConnection = Connect-PnPOnline -Url $OlSiteURL -Credentials $OlCreds
$OlContext = Get-PnPContext
#Disable feature at site collection level to enable modern experience at SC level
Disable-PnPFeature -Identity E3540C7D-6BEA-403C-A224-1A12EAFEE4C4 -Scope Site -Force
#Disable feature at web level to enable modern experience at web level
Disable-PnPFeature -Identity 52E14B6F-B1BB-4969-B89B-C4FAA56745EF -Scope Web -Force
#Enable new experience for all lists
$allLists = Get-PnPList
foreach($list in $allLists)
{
$OlContext.Load($list)
$OlContext.ExecuteQuery()
$list.ListExperienceOptions = "NewExperience"
$list.Update()
$OlContext.ExecuteQuery()
Write-host $list.Title -ForegroundColor Green
}