Created
March 28, 2018 18:26
-
-
Save joerodgers/b564e58db1dbbe2809027867b5505063 to your computer and use it in GitHub Desktop.
Enable or disables the IE11OptOut Feature for a SPO site collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.dll" | |
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll" | |
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials | |
function Enable-SPOFeature | |
{ | |
[cmdletbinding()] | |
param | |
( | |
[parameter(Mandatory=$true)][Microsoft.SharePoint.Client.ClientContext]$ClientContext, | |
[parameter(Mandatory=$true)][System.Guid]$FeatureID, | |
[parameter(Mandatory=$false)][ValidateSet("Site","Web")]$Scope, | |
[parameter(Mandatory=$false)][Switch]$Force | |
) | |
begin | |
{ | |
} | |
process | |
{ | |
Write-Verbose "Activating Feature '$FeatureID' at scope $Scope on $($ClientContext.Url)" | |
switch( $scope ) | |
{ | |
"Web" | |
{ | |
$feature = $ClientContext.Web.Features.Add($FeatureID, $Force.IsPresent, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::Farm) | |
} | |
"Site" | |
{ | |
$feature = $ClientContext.Site.Features.Add($FeatureID, $Force.IsPresent, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::Farm) | |
} | |
} | |
try | |
{ | |
$ClientContext.ExecuteQuery() | |
Write-Verbose "Feature Activation for '$FeatureID' at scope $Scope on $($ClientContext.Url) succeeded." | |
return $true | |
} | |
catch | |
{ | |
Write-Error "Feature Activation for '$FeatureID' at scope $Scope on $($ClientContext.Url) failed. Error: $_" | |
return $false | |
} | |
} | |
end | |
{ | |
} | |
} | |
function Disable-SPOFeature | |
{ | |
[cmdletbinding()] | |
param | |
( | |
[parameter(Mandatory=$true)][Microsoft.SharePoint.Client.ClientContext]$ClientContext, | |
[parameter(Mandatory=$true)][System.Guid]$FeatureID, | |
[parameter(Mandatory=$false)][ValidateSet("Site","Web")]$Scope, | |
[parameter(Mandatory=$false)][Switch]$Force | |
) | |
begin | |
{ | |
} | |
process | |
{ | |
Write-Verbose "Activating Feature '$FeatureID' at scope $Scope on $($ClientContext.Url)" | |
switch( $scope ) | |
{ | |
"Web" | |
{ | |
$feature = $ClientContext.Web.Features.Remove( $FeatureID, $Force.IsPresent ) | |
} | |
"Site" | |
{ | |
$feature = $ClientContext.Site.Features.Remove( $FeatureID, $Force.IsPresent ) | |
} | |
} | |
try | |
{ | |
$ClientContext.ExecuteQuery() | |
Write-Verbose "Feature Deactivation for '$FeatureID' at scope $Scope on $($ClientContext.Url) succeeded." | |
return $true | |
} | |
catch | |
{ | |
Write-Host "Feature Deactivation for '$FeatureID' at scope $Scope on $($ClientContext.Url) failed. Error: $_" | |
return $false | |
} | |
} | |
end | |
{ | |
} | |
} | |
if( -not $credential ) | |
{ | |
$credential = Get-Credential | |
} | |
$siteUrl = "https://contoso.sharepoint.com/sites/teamsite" | |
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) | |
$clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password) | |
# Enable-SPOFeature -ClientContext $clientContext -FeatureID "80E47777-D21C-46E0-9139-7C7741EB4B54" -Scope Site | |
# Disable-SPOFeature -ClientContext $clientContext -FeatureID "80E47777-D21C-46E0-9139-7C7741EB4B54" -Scope Site |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment