SharePoint Online: Change the UI to Modern Experience or Classic Experience using PowerShell
Requirement: Change Classic Experience to Modern Experience and Modern UI to Classic in SharePoint Online.
How to Activate 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 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 to switch back to the new experience in SharePoint Online? To enable the modern experience in SharePoint Online, use the “Exit classic experience” link in the bottom-left corner.
This turns ON the modern experience. How to revert to classic in SharePoint Online? Well, To disable modern experience and switch back to classic in SharePoint Online using the link “Return to Classic SharePoint”.
In case you don’t get the “Return to classic SharePoint” or “Exit classic experience”, chances are it may not have enabled! How to Enable or Disable “Return to Classic SharePoint” in SharePoint Online?
PowerShell to Switch Between Modern Experience and Classic Experiences
To enable the modern experience, we have to disable the classic experience feature. And to disable modern experience, we should re-enable the classic experience feature in SharePoint Online. This PowerShell script is spitted into two different functions.
- Sets the given feature status to enabled or disabled at given scope such as: Site or Web
- Activates the relevant feature at 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 classic view to modern view in SharePoint Online. E.g.
Set-SPOExperience -SiteURL $SiteURL -Experience Classic -Scope Site
This PowerShell script changes the UI experience to classic view in SharePoint Online for all lists and libraries at the given site collection. However, settings at the individual list and library level can override site-wide settings: SharePoint Online: How to Change List UI to Modern Experience?
Similarly, you can switch back to modern view in SharePoint Online subsite with:
Set-SPOExperience -SiteURL $SiteURL -Experience Classic -Scope Site
Set-SPOExperience -SiteURL $SiteURL -Experience Modern -Scope Web
PnP PowerShell to Disable Classic Experience and Enable Modern UI for a Site
PnP PowerShell makes it much simpler to turn classic experience into the modern!
#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!).
Absolutely – Salaudeen Rajack –> you are SharePoint King and helping SharePoint learns a lot – don’t have words to express. Please continue your support. Cheers.
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.
I have solved the issue. Sorry again. By making some modifications. Hope it would be useful for others 🙂
$UserName=”[email protected]”
$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 🙂
Sure, Use:
$DocLibraries = $Ctx.Web.Lists | Where {$_.BaseType -eq “DocumentLibrary” -and $_.Hidden -eq $False}
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
Just set: $List.OnQuickLaunch=$True, refer SharePoint Online: Update List Title, Description, Quick Launch Navigation Properties using PowerShell
Many thanks for the reply.
$List.OnquickLaunch=$True is already set but somehow can not add more than one document library.
Tried $ListName = Import-Csv “C:\Users\ListName.csv” path so it could read from csv, the names of Document Libraries but received the following error.
Error Setting List Properties! Exception calling “ExecuteQuery” with “0” argument(s): “List ‘ ‘ doe
s not exist at site with URL.
Thanks for the support.