Change List/Library to New/Modern Experiences using PowerShell

In this blog we are going to discuss about how to convert the List/Library to classic version in Communication site. We can convert it manually or programmatically using PowerShell.
First we are converting the Modern list/library to classic experience of a site collection and then we will see how to covert classic list/library to modern experiences. We can do this through manual method as well as in 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.

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”

$siteURL = Read-Host “Enter site Url”

$listName= Read-Host “Enter List Name”

$userId= Read-Host “Enter UserName”

$password = Read-Host “Enter password”

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId,(ConvertTo-SecureString $password -AsPlainText -Force))

try {

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)

    $context.Credentials = $credentials

    $oWeb = $Context.web

    $context.Load($oWeb)

    $list = $oWeb.Lists.GetByTitle($listName)

    $list.ListExperienceOptions = “ClassicExperience”

    $list.Update()

    $context.ExecuteQuery()

}

catch {

    }

By the below code, you can convert a classic list/library to new experiences (modern experience).

try {

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)

    $context.Credentials = $credentials

    $oWeb = $Context.web

    $context.Load($oWeb)

    $list = $oWeb.Lists.GetByTitle($listName)

    $list.ListExperienceOptions = “NewExperience”

    $list.Update()

    $context.ExecuteQuery()

}

catch {

    }

Note : You also can do it manually by following the below steps to convert a library to classic experiences.

  1. Go to List/Library Settings by clicking the gear menu of that SharePoint page>> Click on “Advanced Settings
  2. Scroll down, then from “List Experience” Section, Select “Classic Experience

Library in Modern Mode

Library in Classic Mode

Note: If you want to convert a classic list/library to Modern then choose “New Experience “ in “Lis Experience” Section

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.

$siteURL = Read-Host “Enter site Url”

$listName= Read-Host “Enter List Name”

$userId= Read-Host “Enter UserName”

$password = Read-Host “Enter password”

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId,(ConvertTo-SecureString $password -AsPlainText -Force))

try {

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)

    $context.Credentials = $credentials

    $oWeb = $Context.web

    $context.Load($oWeb)

    $context.ExecuteQuery()

    $lists = $oWeb.Lists

    $context.Load($lists)

    $context.ExecuteQuery()

    foreach($list in $lists){

        if($list.ListExperienceOptions -eq “NewExperience” -and ($list.Hidden -eq $false))

    {

            $list.ListExperienceOptions = “ClassicExperience”

                $list.ListExperienceOptions = “ClassicExperience”

                $list.Update()

                $context.ExecuteQuery()

               }

        }

}

catch {

     sleep 5

    }

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”.


Key words:

  1. Change list/library to new experiences using PowerShell
  2. Convert all list/library to classic and new experiences using PowerShell csom
  3. Programmatically convert list/library to classic experiences

Share

Add Your Comments

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