Omar El-Anis – 365 Developer

My experiences with SharePoint, Flows, PowerApps, JavaScript and all of the other lovely web technologies out there!

SharePoint Services SharePoint Useful Tricks Uncategorised

Enable or disable a site feature in SP 2013/Online

Use the code listed in the embed below to add or remove a feature on a site – un-comment the relevant section to set the script to enable or disable the feature

$username = ""<br>
$securePassword = Read-Host -Prompt "Please enter your password" -AsSecureString<br>
$url = ""</p>
<p>$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force</p>
<p>#Below lines are needed if the SharePoint powershell install is not globally defined<br>
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"<br>
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"</p>
<p># connect/authenticate to SharePoint Online and get ClientContext object..<br>
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)<br>
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)<br>
$clientContext.Credentials = $credentials</p>
<p>if (!$clientContext.ServerObjectIsNull.Value)<br>
Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green<br>
$feature=Read-Host -Prompt "Enter the feature id, e.g. for SharePoint Server Publishing it's 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"<br>
$featureguid=new-object System.Guid $feature<br>
$site = $clientContext.Web<br>
#uncomment the line below to disable the feature<br>
#$site.Features.Remove($featureguid, $true);</p>
<p>#uncomment the line below to enable the feature<br>
#$site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::Site)</p>
Write-Host "Feature added/removed for" $site.Url</p>

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments