Follow by Email

Tuesday, May 23, 2017

Disable modern experience for a site collection in SharePoint Online

The post helps you to disable modern experience in SharePoint online at the site collection level or at the web level, it is only settable by CSOM/PowerShell.

Below is the powershell script for the same. It will popup for entering parameters and you are good to go with that, This script let you enable/disable the experience based on your inputs.

function Set-NewExperience{
 
 
    Begin{

$Url = Read-Host -Prompt "Enter web url:"
    $username = Read-Host -Prompt "Enter Username:"
    $password = Read-Host -Prompt "Enter password" -AsSecureString
$Scope = Read-Host -Prompt "Enter scope Site/Web:"
$State = Read-Host -Prompt "Enter scope Disable/Enable:"
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
    $context.Credentials = $credentials
    }
    Process{

        if($Scope -eq "Site"){
            # To apply the script to the site collection level, uncomment the next two lines.
            $site = $context.Site
            $featureguid = new-object System.Guid "E3540C7D-6BEA-403C-A224-1A12EAFEE4C4"
        }
        else{
            # To apply the script to the website level, uncomment the next two lines, and comment the preceding two lines.
            $site = $context.Web
            $featureguid = new-object System.Guid "52E14B6F-B1BB-4969-B89B-C4FAA56745EF"
        }
        if($State -eq "Disable")
        {
            # To disable the option to use the new UI, uncomment the next line.
            $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
            $message = "New library experience has been disabled on $URL"
        }
        else{
            # To re-enable the option to use the new UI after having first disabled it, uncomment the next line.
            # and comment the preceding line.
            $site.Features.Remove($featureguid, $true)
            $message = "New library experience has been enabled on $URL"
        }
        try{
            $context.ExecuteQuery()
            write-host -ForegroundColor Green $message
        }
        catch{
            Write-Host -ForegroundColor Red $_.Exception.Message
        }
    }
    End{
        $context.Dispose()  
    }
}

Set-NewExperience

No comments:

Post a Comment