SharePoint Online: Change from Classic Experience to Modern (and vice versa) using PowerShell

Requirement: Change SharePoint Online site from Classic Experience to Modern.

How to Activate the Modern Experience from Classic?

The modern experience in SharePoint Online lists and libraries is faster, mobile-friendly, and easier to use. It brings new functionalities, user interfaces, and components. However, some features can only be used in the classic experience. So, you may need to switch between modern UI and classic experience in SharePoint Online. How do I change from the classic to the modern view in SharePoint? To enable the new modern library experience in SharePoint Online, use the “Exit classic experience” link in the bottom-left corner.

sharepoint online disable modern experience

This turns ON the modern experience. How to revert to classic in SharePoint Online? Well, To disable the modern experience and switch back to classic in SharePoint Online, use the link “Return to Classic SharePoint”.

sharepoint online enable modern experience

In case you don’t get the “Return to classic SharePoint” or “Exit classic experience”, chances are it may not have been enabled! How to Enable or Disable “Return to Classic SharePoint” in SharePoint Online?

Please note, this script doesn’t convert your classic team site home page to modern. You have to create a new modern page and set it as Home page!

PowerShell to Switch from Classic to Modern Experience

To enable the modern experience, we have to disable the classic experience feature. And to disable the modern experience, we should re-enable the classic experience feature in SharePoint Online. This PowerShell script is spitted into two different functions.

  1. Sets the given feature status to enabled or disabled at the given scope, such as Site or Web.
  2. Activates the relevant feature at the appropriate scope(s) to set the UI experience.

You can use this PowerShell script to enable or disable modern experience at site collection or site levels. This script sets either modern experience or classic experience on objects: Lists and libraries (If the list experience settings is: “Default experience for the site”), Site contents, site usage, Recycle Bin, etc.

#Load SharePoint CSOM Assemblies
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"

#Function to Enable or Disable Feature in SharePoint Online
Function Set-SPOFeatureStatus
{
    [CMDLetBinding()]
    Param
    (
        [Parameter(Mandatory=$True)][Microsoft.SharePoint.Client.ClientContext]$Context,
        [Parameter(Mandatory=$True)][GUID]$FeatureGUID,
        [Parameter(Mandatory=$True)][ValidateSet('Site','Web')][String]$Scope,
        [Parameter(Mandatory=$True)][ValidateSet('Enable','Disable')][String]$Status
    )
    If($Scope -eq "Site")
    {
        #Get the Site
        $Site = $Context.Site
        #Get the Feature Status
        $FeatureStatus =  $Site.Features.GetById($FeatureGuid)
        $FeatureStatus.Retrieve("DefinitionId")
        $Context.Load($FeatureStatus)
        $Context.ExecuteQuery()

        If($Status -eq "Enable")
        {
            #Activate the feature if its not enabled already
            If($FeatureStatus.DefinitionId -eq $null)
            {
                #Enable the Feature
                $Site.Features.Add($FeatureGuid, $True, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null
                $Context.ExecuteQuery()
                Write-host -f Green "`tFeature has been Enabled at Site Level!"
            }
            Else
            {
                Write-host -f Yellow "`tFeature is Already Enabled at Site Level!"
            }
        }
        Elseif($Status -eq "Disable")
        {
            #De-Activate the feature if its enabled already
            If($FeatureStatus.DefinitionId -ne $null)
            {
                #Disable feature
                $Site.Features.Remove($FeatureGuid, $True) | Out-Null
                $Context.ExecuteQuery()
                Write-host -f Green "`tFeature has been Disabled at Site Level!"
            }
            Else
            {
                Write-host -f Yellow "`tFeature is Already Disabled at Site Level!"
            }
        }
    }
    ElseIf($Scope -eq "Web")
    {
        #Get the web
        $Web = $Context.Web
        #Get the Feature Status
        $FeatureStatus =  $Web.Features.GetById($FeatureGUID)
        $FeatureStatus.Retrieve("DefinitionId")
        $Context.Load($FeatureStatus)
        $Context.ExecuteQuery()
    
        If($Status -eq "Enable")
        {
            #Activate the feature if its not enabled already
            If($FeatureStatus.DefinitionId -eq $null)
            {
                #Enable Feature
                $Web.Features.Add($FeatureGUID, $True, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)| Out-Null
                $Context.ExecuteQuery()
                Write-host -f Green "`tFeature has been Enabled at Web Level!"
            }
            Else
            {
                Write-host -f Yellow "`tFeature is Already Enabled at Web Level!"
            }
        }
        ElseIf($Status -eq "Disable")
        {
            #De-Activate the feature if its enabled already
            If($FeatureStatus.DefinitionId -ne $null)
            {
                #Disable Classic Experience feature, which Enables Modern UI
                $Web.Features.Remove($FeatureGUID, $True) | Out-Null                
                $Context.ExecuteQuery()
                Write-host -f Green "`tFeature has been Disabled at Web Level!"   
            }
            Else
            {
                Write-host -f Yellow "`tFeature is Already Disabled at Web Level!"
            }
        }
    }
}

#Function to set UI  experience to Modern or Classic at Site or Web Level
Function Set-SPOUIExperience
{
    [CMDLetBinding()]
    Param
    (
        [String]$SiteURL, 
        [Parameter(Mandatory=$True)][ValidateSet('Modern','Classic')][String]$Experience,
        [Parameter(Mandatory=$True)][ValidateSet('Site','Web')][String]$Scope
    )

    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Site Scoped Feature "EnableDefaultListLibrarExperience" - Classic Experience
        $SiteFeatureGuid = New-Object System.Guid "E3540C7D-6BEA-403C-A224-1A12EAFEE4C4"
        
        #Web Scoped Feature "EnableDefaultListLibrarExperience" - Classic Experience
        $WebFeatureGUID = New-Object System.Guid "52E14B6F-B1BB-4969-B89B-C4FAA56745EF" 

        #Enable or Disable Modern Experience based on the parameters
        If($Scope -eq "Site")
        {
            #Get the web
            $Web = $Ctx.Web
            $Ctx.Load($Web)
            $Ctx.ExecuteQuery()

            If($Experience -eq "Modern")
            { 
                #Disable Classic Experience feature at site level
                Write-host -f Green "Enabling Modern Experience at the Site Collection by Disabling Classic UI Feature..."
                Set-SPOFeatureStatus -Context $Ctx -FeatureGUID $SiteFeatureGuid -Scope Site -Status Disable

                #Disable Classic Experience feature at web level
                Set-SPOUIExperience $Web.URL -Experience $Experience -Scope Web

                #Process each subsite in the site
                $Subsites = $Web.Webs
                $Ctx.Load($Subsites)
                $Ctx.ExecuteQuery()        
                Foreach ($SubSite in $Subsites)
                {
                    #Call the function Recursively
                    Set-SPOUIExperience $SubSite.URL -Experience $Experience -Scope Web
                }
            }
            ElseIf($Experience -eq "Classic")
            {
                #Enable Classic Experience feature at site level
                Write-host -f Green "Enabling Classic Experience at the Site Collection..."
                Set-SPOFeatureStatus -Context $Ctx -FeatureGUID $SiteFeatureGuid -Scope Site -Status Enable                
                
                #Enable Classic Experience feature at web level
                Set-SPOUIExperience $Web.URL -Experience $Experience -Scope Web

                #Process each subsite in the site
                $Subsites = $Web.Webs
                $Ctx.Load($Subsites)
                $Ctx.ExecuteQuery()        
                Foreach ($SubSite in $Subsites)
                {
                    #Call the function Recursively
                    Set-SPOUIExperience $SubSite.URL -Experience $Experience -Scope Web
                }
            }
        }
        ElseIf($Scope -eq "Web")
        {
            If($Experience -eq "Modern")
            {
                #Disable Classic Experience
                Write-host -f Green "Enabling Modern Experience at the Web $($SiteURL) by Disabling Classic UI Feature..."
                Set-SPOFeatureStatus -Context $Ctx -FeatureGUID $WebFeatureGUID -Scope Web -Status Disable                
            }
            ElseIf($Experience -eq "Classic")
            {
                #Enable Classic Experience
                Write-host -f Green "Enabling Classic Experience at the Web $($SiteURL)"
                Set-SPOFeatureStatus -Context $Ctx -FeatureGUID $WebFeatureGUID -Scope Web -Status Enable
            }
        }
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}

#Set Variable
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"

#Get Credentials to connect
$Cred = Get-Credential

#Call the function to set UI experience
Set-SPOUIExperience -SiteURL $SiteURL -Experience Modern -Scope Site

When you activate the site-level feature, the new sites you create follow the UI experience set. Similarly, web-level feature sets the UI experience on existing webs.

How to change the classic view to the modern view in SharePoint Online?

You can call the function with relevant parameters to change the classic view to modern view in SharePoint sites. E.g.,

Set-SPOUIExperience -SiteURL $SiteURL -Experience Modern -Scope Site

This PowerShell script changes the UI experience from the classic view to the modern, for all lists and libraries at the given site collection. However, advanced settings at the individual list and library level can override site-wide settings. Use this script to update library settings: SharePoint Online: How to Change List UI to Modern Experience?

Similarly, you can switch back to the classic experience from the modern view in SharePoint Online site with:

Set-SPOUIExperience -SiteURL $SiteURL -Experience Classic -Scope Site

PnP PowerShell to Disable Classic Experience and Enable Modern UI for a Site

PnP PowerShell makes it much simpler to turn the classic site into the modern one.

#Parmeter
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing/townhall"

#Connect to Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Disable Modern UI Blocking Features at both Site and Web Level
Disable-PnPFeature -Identity "E3540C7D-6BEA-403C-A224-1A12EAFEE4C4" -Scope Site
Disable-PnPFeature -Identity "52E14B6F-B1BB-4969-B89B-C4FAA56745EF" -Scope Web

Please note, You must disable the feature at the site level as well, even if you want to disable classic UI at one specific subsite! (As the feature scoped at site collection is inherited by the subsite!). Furthermore, this script doesn’t change any classic SharePoint pages (including the Home page, Publishing pages, wiki pages, web part pages, and site pages library) into modern pages. To get a modern home page, You must use: How do I convert a classic page to a modern page in SharePoint Online?

How do I change a modern site to a classic site in SharePoint Online?

If you want to go back to the classic user experience from modern team sites, use: SharePoint Online switch to classic view. You can still create new sites using the classic site template.

How do I change the Root site to a modern Communication site in SharePoint Online?

To change the root site (or any team site) to the communication site, use the “Enable-SPOCommSite” cmdlet. You can also replace a classic SharePoint site with a modern one in the SharePoint Admin center.
More info: Convert Root site to Communication site in SharePoint Online

How do I create a modern page on the SharePoint Classic site?

To create modern pages in Classic SharePoint Online sites: Activate the web-scoped feature “Site Pages” first. Once you have enabled the feature, You’ll find “Page” listed on the Site contents page or in your site’s “Site Pages” library.
More info: SharePoint Online Add a modern page to the classic site

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

7 thoughts on “SharePoint Online: Change from Classic Experience to Modern (and vice versa) using PowerShell

  • Absolutely – Salaudeen Rajack –> you are SharePoint King and helping SharePoint learns a lot – don’t have words to express. Please continue your support. Cheers.

    Reply
  • Many thanks Salaudeen 🙂

    Implemented this method.

    ForEach($List in $Lists)

    {

    if([int]$list.BaseTemplate -eq 101)

    {

    $listcount +=1
    Write-Host ” – “$List.Title

    $List.OnQuickLaunch=$True
    $List.Update()

    }

    }

    Your blog is golden resource for CSOM users.

    Reply
  • I have solved the issue. Sorry again. By making some modifications. Hope it would be useful for others 🙂

    $UserName=”admin@tenant.onmicrosoft.com”
    $Password =”****”

    #Setup Credentials to connect
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

    Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the web and List
    $Web=$Ctx.Web

    $Lists = $Ctx.Web.Lists
    $Ctx.Load($Lists)
    $Ctx.ExecuteQuery()

    ForEach($List in $Lists)
    {
    #Get the List Name
    $List.OnQuickLaunch=$True
    $List.Update()
    }

    $Ctx.ExecuteQuery()

    }

    catch {
    write-host “Error: $($_.Exception.Message)” -foregroundcolor Red
    }

    Have to sort only document libraries from those lists. Hopefully I will make it 🙂

    Reply
    • Sure, Use:
      $DocLibraries = $Ctx.Web.Lists | Where {$_.BaseType -eq “DocumentLibrary” -and $_.Hidden -eq $False}

      Reply
  • Hi, the question is not relevant with the topic I was wondering is there any documentation for Bulk adding document libraries to quick launch menu using SharePoint Online ? Thanks

    Reply

Leave a Reply

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