0

I'm using this PowerShell/CSOM script to return a the GUIDs of the features on my SharePoint site. It works as expected, however I would like to get the name of the feature as well. Here is the example output:

enter image description here

Which is generated by this snippet:

enter image description here

I can see that these are the members of the SPFeature class: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfeature_members.aspx

Am I able to use any of these to spit out the name of the feature?

1 Answer 1

0

I've done it this way for our PS module.

Function Get-Features {
    <#
        .SYNOPSIS
        Gets all the site or web features
        .DESCRIPTION    
        Gets all the site or web scoped features of a site, useful in conjunction with Set-SiteCollectionFeature or Set-SiteFeature
        .PARAMETER Url
        The Url of the site
        .PARAMETER Scope
        The type of features being requested
        .EXAMPLE
        Can be used in variable assignment
        $features = Get-Features -Url "https://tenant.sharepoint.com/teams/eric" -Scope Site
        .EXAMPLE
        Can output a list of features
        Get-Features -Url "https://tenant.sharepoint.com/teams/eric" -Scope Web
    #>
    Param(
        [Parameter(Mandatory=$true,HelpMessage="The URL of the site")][ValidateNotNull()]
        [string]$Url,

        [Parameter(Mandatory=$true,HelpMessage="The type of features being requested")][ValidateSet("Web","Site")]
        [string]$Scope
    )
    Begin{
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)  
        $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)

        if($Scope -eq "Web"){
            $webFeatures = $context.Web.Features
        }
        else {
            $webFeatures = $context.Site.Features
        }
        $context.Load($webFeatures)
        $context.ExecuteQuery()
    }
    Process{
        foreach($feature in $webFeatures){
            #$feature.DefinitionId
            Get-CSOMProperties -object $feature -propertyNames @("DisplayName", "DefinitionId") -executeQuery
            $feature | select DisplayName,DefinitionId   
        }
    }
    End{
        $context.Dispose()
    }
}

It utilizes the Get-CSOMProperties function as detailed on ITUnity. I believe I adapted ours from the article you reference.

3
  • Hi Eric, getting this error: The term 'Get-CSOMProperties' is not recognized as the name of a cmdlet. Any ideas?
    – Ray Hogan
    May 13, 2016 at 10:31
  • I've looked at the ITUnity page and I'm unsure of what snippet I need to put inside a new function called 'Get-CSOMProperties '. Any ideas?
    – Ray Hogan
    May 13, 2016 at 10:38
  • For Get-CSOMProperties he references above, look at "Load-CSOMProperties" on this guy's github: github.com/benstegink/PowerShellScripts/blob/master/Office365/… Sourcing: benstegink for saving the script to github and originally Gary LaPointe on ITUnity
    – sleetish
    Mar 1, 2019 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.