3

I've written a CSOM script for Powershell (code below) to enumerate the features activated on a given site. When in the foreach loop I use $f.DefinitionId, I get a list of the feature GUIDs... however if I swap this for $f.DisplayName it outputs nothing (no errors).

I'm confused as to how this can be because the DisplayName property is listed on the class reference for MS.SP.Client.Feature and is picked up as a valid choice by the Powershell ISE IntelliSense.

Have tried it on two different tenants (the former where I have site collection admin only; the latter where I have full tenant admin) both with the same result.

EDIT: I checked the output of $f with Select-Object and it appears DisplayName is there, just blank... so any idea why? I had tried assigning $f.DisplayName to a variable and loading it via $ctx.Load but this produces a 'cannot find an overload' error.

enter image description here

Any ideas?

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';

$password = Read-Host -Prompt "Enter password" -AsSecureString;
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("admin@xxx.onmicrosoft.com", $password);
$siteUrl = "https://xxx.sharepoint.com/";

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl);
$ctx.Credentials = $credentials;

$thisSite = $ctx.Web;
$ctx.Load($thisSite);
$ctx.ExecuteQuery();

$fList = $thisSite.Features;
$ctx.load($fList);
$ctx.ExecuteQuery();

foreach ($f in $fList) {
    $ctx.load($f)
    $ctx.ExecuteQuery()
    $f.DisplayName
}
2

You need to explicitly load the display name property of the feature. In CSOM unlike SSOM, it (mostly) only gives you only the properties that you ask for.

Try either of the below two approaches, should work:

foreach ($f in $fList) {
    $f.Retrieve("DisplayName")  
    $ctx.load($f)   
    $ctx.ExecuteQuery()
    $f.DisplayName
}

Or

foreach ($f in $fList) {
    $f.Retrieve("DisplayName")  
    $ctx.load($f)   
    $ctx.load($f.DisplayName)
    $ctx.ExecuteQuery()
    $f.DisplayName
}

Reference for part 1 - Get SharePoint Online Site and Web Feature using CSOM and PowerShell

  • Second one I'd already tried to no avail, but the first one works, cheers! – Thomas Gass Aug 22 '17 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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