Enable Site Collection Features SharePoint via PowerShell

devopsfj 256 Reputation points
2023-11-24T10:47:57.43+00:00

Hello,

I am looking to enable Site Collection Features via PowerShell on a modern site, however, there seems no option to achieve this with either SP or PnP PowerShell Modules?

I am trying to enable the below Site Collection Features:

User's image

How can this be achieved via PowerShell?

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Emily Du-MSFT 51,836 Reputation points Microsoft External Staff
    2023-11-27T03:02:29.89+00:00

    1.For In Place Records Management feature, please run below PowerShell.

    #Variables for Processing
    $SiteURL = "https:/tenant.sharepoint.com/sites/emilytestnew"
    $FeatureGUID =[System.GUID]("da2e115b-07e4-49d9-bb2c-35e93bb9fca9")
    $LoginName ="******@tenant.onmicrosoft.com"
    $LoginPassword ="LoginPassword"
     
    #Get the Client Context
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
     
    #Login Credentials
    $SecurePWD = ConvertTo-SecureString $LoginPassword -asplaintext -force 
    $Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $LoginName, $SecurePWD
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.UserName,$Credential.Password)
     
    #Get the Site
    $site = $ctx.site
     
    #sharepoint online powershell activate feature
    $site.Features.Add($FeatureGUID, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::farm)   
     
    $ctx.ExecuteQuery() 
    write-host "Feature has been Activated!"
    

    2.For Library and Folder Based Retention feature, please run below PowerShell.

    #Variables for Processing
    $SiteURL = "https://tenant.sharepoint.com/sites/emilytestnew"
    $FeatureGUID =[System.GUID]("063c26fa-3ccc-4180-8a84-b6f98e991df3")
    $LoginName ="******@tenant.onmicrosoft.com"
    $LoginPassword ="LoginPassword"
     
    #Get the Client Context
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
     
    #Login Credentials
    $SecurePWD = ConvertTo-SecureString $LoginPassword -asplaintext -force 
    $Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $LoginName, $SecurePWD
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.UserName,$Credential.Password)
     
    #Get the Site
    $site = $ctx.site
     
    #sharepoint online powershell activate feature
    $site.Features.Add($FeatureGUID, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::farm)   
     
    $ctx.ExecuteQuery() 
    write-host "Feature has been Activated!"
    

    3.Result:

    1

    2

    3


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. devopsfj 256 Reputation points
    2023-11-29T10:36:17.4666667+00:00

    Hey.

    Thanks for the response, I actually ended up finding a more simple method using PnP:

    Enable-PnPFeature -Identity <GUID> -Force -Scope Site

    I was missing -Scope Site before which was why it was not working.

    Thanks!


  3. Emily Du-MSFT 51,836 Reputation points Microsoft External Staff
    2023-11-30T02:49:31.3533333+00:00

    I'm glad to hear you solve the problem and make a brief summary. If you have any remaining issue about this question, you are welcome to discuss in this post.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others.". You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

    [Enable Site Collection Features SharePoint via PowerShell]

    Issue Symptom:

    OP is looking to enable Site Collection Features via PowerShell on a modern site, however, there seems no option to achieve this with either SP or PnP PowerShell Modules.

    OP is trying to enable the below Site Collection Features:

    User's image

    How can this be achieved via PowerShell?

    Current status:

    OP ended up finding a simpler method using PnP:

    Enable-PnPFeature -Identity <GUID> -Force -Scope Site

    OP was missing -Scope Site before which was why it was not working.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.