Forum Discussion
Activate SharePoint online Site Collection feature across all sites in a MFA enabled O365 tenant
Has anyone tried to activate a site collection level feature across all sites in MFA enabled SP Online environment ? I'm getting the following error
Error -------------------------------------------------------------------------------------------------------
Connect-SPOService : The sign-in name or password does not match one in the Microsoft account system.
At line:55 char:1
+ Connect-SPOService -URL $AdminSiteURL -Credential $Credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-SPOService], IdcrlException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.IdcrlException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService
Get-SPOSite : No connection available. Use Connect-SPOService before running this CmdLet.
At line:58 char:19
+ ForEach($Site in (Get-SPOSite -Limit ALL))
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-SPOSite], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Online.SharePoint.PowerShell.GetSite
----------------------------------------------------------------------------------------------------------------
Script -------------------
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
Function Activate-SPOFeature
{
Param ($SiteURL,$FeatureGuid)
Try
{
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.Username, $Credential.Password)
$Ctx.Credentials = $Credentials
$Site=$Ctx.Site
#Get the Feature
$Feature = $Site.Features.GetById($FeatureGuid)
$Ctx.Load($Feature)
$Ctx.ExecuteQuery()
#Activate the feature if its not activated already
Write-Host "Activating Feature $($FeatureStatus.DisplayName) in Site $SiteURL"
if($Feature.DefinitionId -eq $null)
{
#sharepoint online powershell open in client application
$Site.Features.Add($FeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null
$Ctx.ExecuteQuery()
Write-Host "`t Feature Activated!" -ForegroundColor Green
}
else
{
Write-host "`t Feature is Already Active on the Site collection!" -ForegroundColor Yellow
}
}
Catch
{
write-host "Error Activating Feature: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Parameters to Activate Feature
$AdminSiteURL = "https://testdomain-admin.sharepoint.com/"
$FeatureGuid= [System.Guid] ("8a4b8de2-6fd8-41e9-923c-c7c3c00f8295")
#Get Credentials to connect
#$Credential = Get-Credential
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $User, $Password
#Connect To SharePoint Online Admin Center
Connect-SPOService -URL $AdminSiteURL -Credential $Credential
#Get All Site collection and loop through
ForEach($Site in (Get-SPOSite -Limit ALL))
{
#Activate Feature
Activate-SPOFeature -Site $Site.URL -FeatureGuid $FeatureGuid
}