Activate SharePoint online Site Collection feature across all sites in a MFA enabled O365 tenant

%3CLINGO-SUB%20id%3D%22lingo-sub-1149263%22%20slang%3D%22en-US%22%3EActivate%20SharePoint%20online%20Site%20Collection%20feature%20across%20all%20sites%20in%20a%20MFA%20enabled%20O365%20tenant%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1149263%22%20slang%3D%22en-US%22%3E%3CP%3EHas%20anyone%20tried%20to%20activate%20a%20site%20collection%20level%20feature%20across%20all%20sites%20in%20MFA%20enabled%20SP%20Online%20environment%20%3F%20I'm%20getting%20the%20following%20error%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EError%20-------------------------------------------------------------------------------------------------------%3C%2FP%3E%3CP%3E%3CFONT%3EConnect-SPOService%20%3A%20The%20sign-in%20name%20or%20password%20does%20not%20match%20one%20in%20the%20Microsoft%20account%20system.%3CBR%20%2F%3EAt%20line%3A55%20char%3A1%3CBR%20%2F%3E%2B%20Connect-SPOService%20-URL%20%24AdminSiteURL%20-Credential%20%24Credential%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20NotSpecified%3A%20(%3A)%20%5BConnect-SPOService%5D%2C%20IdcrlException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20Microsoft.SharePoint.Client.IdcrlException%2CMicrosoft.Online.SharePoint.PowerShell.ConnectSPOService%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3EGet-SPOSite%20%3A%20No%20connection%20available.%20Use%20Connect-SPOService%20before%20running%20this%20CmdLet.%3CBR%20%2F%3EAt%20line%3A58%20char%3A19%3CBR%20%2F%3E%2B%20ForEach(%24Site%20in%20(Get-SPOSite%20-Limit%20ALL))%3CBR%20%2F%3E%2B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20NotSpecified%3A%20(%3A)%20%5BGet-SPOSite%5D%2C%20InvalidOperationException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20System.InvalidOperationException%2CMicrosoft.Online.SharePoint.PowerShell.GetSite%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3E----------------------------------------------------------------------------------------------------------------%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3EScript%20-------------------%3C%2FFONT%3E%3C%2FP%3E%3CDIV%3E%3CFONT%3EAdd-Type%20-Path%20'C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C16%5CISAPI%5CMicrosoft.SharePoint.Client.dll'%26nbsp%3B%3CBR%20%2F%3EAdd-Type%20-Path%20'C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C16%5CISAPI%5CMicrosoft.SharePoint.Client.Runtime.dll'%26nbsp%3B%3CBR%20%2F%3EAdd-Type%20-Path%20'C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C16%5CISAPI%5CMicrosoft.SharePoint.Client.UserProfiles.dll'%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3EFunction%20Activate-SPOFeature%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Param%20(%24SiteURL%2C%24FeatureGuid)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Try%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23Setup%20the%20context%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Ctx%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24Credential.Username%2C%20%24Credential.Password)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Ctx.Credentials%20%3D%20%24Credentials%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Site%3D%24Ctx.Site%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23Get%20the%20Feature%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Feature%20%3D%26nbsp%3B%20%24Site.Features.GetById(%24FeatureGuid)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Ctx.Load(%24Feature)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Ctx.ExecuteQuery()%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23Activate%20the%20feature%20if%20its%20not%20activated%20already%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Write-Host%20%22Activating%20Feature%20%24(%24FeatureStatus.DisplayName)%20in%20Site%20%24SiteURL%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if(%24Feature.DefinitionId%20-eq%20%24null)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23sharepoint%20online%20powershell%20open%20in%20client%20application%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Site.Features.Add(%24FeatureGuid%2C%20%24true%2C%20%5BMicrosoft.SharePoint.Client.FeatureDefinitionScope%5D%3A%3ANone)%20%7C%20Out-Null%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24Ctx.ExecuteQuery()%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Write-Host%20%22%60t%20Feature%20Activated!%22%20-ForegroundColor%20Green%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20else%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Write-host%20%22%60t%20Feature%20is%20Already%20Active%20on%20the%20Site%20collection!%22%20-ForegroundColor%20Yellow%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Catch%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20write-host%20%22Error%20Activating%20Feature%3A%20%24(%24_.Exception.Message)%22%20-foregroundcolor%20Red%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%23Parameters%20to%20Activate%20Feature%3CBR%20%2F%3E%24AdminSiteURL%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Ftestdomain-admin.sharepoint.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Ftestdomain-admin.sharepoint.com%2F%3C%2FA%3E%22%3CBR%20%2F%3E%24FeatureGuid%3D%20%5BSystem.Guid%5D%20(%228a4b8de2-6fd8-41e9-923c-c7c3c00f8295%22)%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%23Get%20Credentials%20to%20connect%3CBR%20%2F%3E%23%24Credential%20%3D%20Get-Credential%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3E%24user%20%3D%20'me%40test.onmicrosoft.com'%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3E%24Password%20%3D%20Read-Host%20-Prompt%20'Please%20enter%20your%20password'%20-AsSecureString%26nbsp%3B%3CBR%20%2F%3E%24Credential%20%3D%20New-Object%20System.Management.Automation.PSCredential%20-ArgumentList%20%24User%2C%20%24Password%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%23Connect%20To%20SharePoint%20Online%20Admin%20Center%3CBR%20%2F%3EConnect-SPOService%20-URL%20%24AdminSiteURL%20-Credential%20%24Credential%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3E%23Get%20All%20Site%20collection%20and%20loop%20through%3CBR%20%2F%3EForEach(%24Site%20in%20(Get-SPOSite%20-Limit%20ALL))%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23Activate%20Feature%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Activate-SPOFeature%20-Site%20%24Site.URL%20-FeatureGuid%20%24FeatureGuid%3CBR%20%2F%3E%7D%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1149263%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Emfa%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPermissions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESecurity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Contributor

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.dll' 
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
$user = 'me@test.onmicrosoft.com'
$Password = Read-Host -Prompt 'Please enter your password' -AsSecureString 
$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
}
0 Replies