Change List/Library To New/Modern Experiences Using PowerShell

Introduction

 
In this blog, we are going to discuss how to convert the List/Library to the classic version on the Communication site. We can convert it manually or programmatically using PowerShell.

First, we are converting the Modern list/library to the classic experience of a site collection and then we will see how to covert the classic list/library of modern experiences. We can do this through the manual method as well as in the coding (PowerShell) method.
 

Convert A list/library of a site collection to Classic or New experiences

 
By using the below code, you can convert a modern list/library to classic experiences,
  1. Add - Type - Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
  2. Add - Type - Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
  3. $siteURL = Read - Host "Enter site Url"  
  4. $listName = Read - Host "Enter List Name"  
  5. $userId = Read - Host "Enter UserName"  
  6. $password = Read - Host "Enter password"  
  7. $credentials = New - Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, (ConvertTo - SecureString $password - AsPlainText - Force))  
  8. try {  
  9.     $context = New - Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
  10.     $context.Credentials = $credentials  
  11.     $oWeb = $Context.web  
  12.     $context.Load($oWeb)  
  13.     $list = $oWeb.Lists.GetByTitle($listName)  
  14.     $list.ListExperienceOptions = "ClassicExperience"  
  15.     $list.Update()  
  16.     $context.ExecuteQuery()  
  17. catch {}  
By the below code, you can convert a classic list/library to new experiences (modern experience),
  1. try {  
  2.     $context = New - Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
  3.     $context.Credentials = $credentials  
  4.     $oWeb = $Context.web  
  5.     $context.Load($oWeb)  
  6.     $list = $oWeb.Lists.GetByTitle($listName)  
  7.     $list.ListExperienceOptions = "NewExperience"  
  8.     $list.Update()  
  9.     $context.ExecuteQuery()  
  10. catch {}  
Note
You also can do it manually by following the below steps to convert a library to classic experiences,
  • Go to List/Library Settings by clicking the gear menu of that, SharePoint page>> Click on “Advanced Settings”.
  • Scroll down, then from the “ListExperience” section, select “Classic Experience.
Change List/Library to New/Modern Experiences using PowerShell
Library in Modern Mode
 
Change List/Library to New/Modern Experiences using PowerShell
 
Library in Classic Mode
 
Change List/Library to New/Modern Experiences using PowerShell 
 
Note
If you want to convert a classic list/library to Modern then choose “New Experience “in the “List Experience” Section.
 
Change List/Library to New/Modern Experiences using PowerShell
 

Convert All list/library of a site collection to Classic or New experiences

 
Follow the below code to convert all the Modern list/library of a site collection to classic experiences.
  1. $siteURL = Read - Host "Enter site Url"  
  2. $listName = Read - Host "Enter List Name"  
  3. $userId = Read - Host "Enter UserName"  
  4. $password = Read - Host "Enter password"  
  5. $credentials = New - Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, (ConvertTo - SecureString $password - AsPlainText - Force))  
  6. try {  
  7.     $context = New - Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
  8.     $context.Credentials = $credentials  
  9.     $oWeb = $Context.web  
  10.     $context.Load($oWeb)  
  11.     $context.ExecuteQuery()  
  12.     $lists = $oWeb.Lists  
  13.     $context.Load($lists)  
  14.     $context.ExecuteQuery()  
  15.     foreach($list in $lists) {  
  16.         if ($list.ListExperienceOptions - eq "NewExperience" - and($list.Hidden - eq $false)) {  
  17.             $list.ListExperienceOptions = "ClassicExperience"  
  18.             $list.ListExperienceOptions = "ClassicExperience"  
  19.             $list.Update()  
  20.             $context.ExecuteQuery()  
  21.         }  
  22.     }  
  23. catch {  
  24.     sleep 5  
  25. }  
Note
If you want to convert a classic list/library to Modern, then in the coding of “$list. ListExperienceOptions ="ClassicExperience"change the ListExperienceOptionsClaasicExperience” to “NewExperience”.