Change Modern UX To Classic UX Using PowerShell

The experience of SharePoint Online is user specific. Many times, we get the requirement of making Classic Experience for all the users. While using Classic Experience, we can customize branding. There are two ways to do it.

Admin Portal > Settings > Organization Profile > Change Experience

But to change the settings from Organization Profile, we need Global Admin Role. Here, we are stuck; not all clients provide Global Admin Role. Don’t worry!!! We can do this using SharePoint Online Management Shell, which uses PowerShell script.

Here is the script.

  1. Add-Type “C:/Program Files/SharePoint Online Management Shell/Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll”  
  2. Add-Type “C:/Program Files/SharePoint Online Management Shell/Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll”  
  3. $url = “(sitecollection_url)”;  
  4. $user = Read-Host -Prompt “Enter User Name”;  
  5. $pwd = Read-Host -Prompt “Enter Password” -AsSecureString;  
  6. [Microsoft.SharePoint.Client.ClientContext]$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url);  
  7. $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user, $pwd);  
  8. $site = $ctx.Site;  
  9. $ctx.load($site);  
  10. $featureguid = New-Object System.Guid ”E3540C7D-6BEA-403C-A224-1A12EAFEE4C4”  
  11. $site.Features.Add($featureguid,$true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None);  
  12. $ctx.ExecuteQuery();  

Explanation

Add-Type will load Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll to the session. These dll files will be automatically added to C drive with SharePoint Online Management Shell installation.

$ is used to declare variables. Read-Host will read input from user and -Prompt will prompt a window for user input.

[Microsoft.SharePoint.Client.ClientContext]$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url) -- with this we are creating an object of type ClientContext and passing site url to the object.

$ctx.Credentials and $ctx.Site are properties of object $ctx , and with these we are passing credentials to the object and creating a new variable named $site for Site property of context. $ctx.load($site) will load the site for current context.

$featureguid = New-Object System.Guid will create new variable of type System Guid and pass the value ‘E3540C7D-6BEA-403C-A224-1A12EAFEE4C4’. This Id is specific for Classic UX.

$site.Features.Add($featureguid,$true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None); will add the feature to the site and $ctx.ExecuteQuery(); will execute our query to the context.