SharePoint Online: Change 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 new experience in SharePoint Online? To enable modern experience in SharePoint Online, use the link "Exit classic Experience" at the bottom left corner.
This turns ON modern experience. How to revert back to classic in SharePoint Online? Well, To disable modern experience and switch back to classic in SharePoint Online use the link "Return to Classic SharePoint".
PowerShell to Switch Between Modern Experience and Classic Experiences
To enable modern experience, we have to disable 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.
How to change classic view to 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.
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 new experience in SharePoint Online? To enable modern experience in SharePoint Online, use the link "Exit classic Experience" at the bottom left corner.
This turns ON modern experience. How to revert back to classic in SharePoint Online? Well, To disable modern experience and switch back to classic in SharePoint Online use the link "Return to Classic SharePoint".
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 Between Modern Experience and Classic Experiences
To enable modern experience, we have to disable 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.
#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 SiteWhen you activate the site level feature, it makes sure new sites you create follow the UI experience set. Similarly, web level feature sets UI experience on existing webs.
How to change classic view to 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 SiteThis PowerShell script change 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 Modern -Scope Web
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
ReplyDeleteJust set: $List.OnQuickLaunch=$True, refer http://www.sharepointdiary.com/2017/04/sharepoint-online-set-list-title-description-quick-launch-navigation-using-powershell.html
DeleteMany thanks for the reply.
Delete$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.
I have solved the issue. Sorry again. By making some modifications. Hope it would be useful for others :)
ReplyDelete$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:
Delete$DocLibraries = $Ctx.Web.Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}
Many thanks Salaudeen :)
ReplyDeleteImplemented 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.
Absolutely - Salaudeen Rajack --> you are SharePoint King and helping SharePoint learns a lot - don't have words to express. Please continue your support. Cheers.
ReplyDelete