1

I'm trying to find a way to enable modern audience targeting on the Site Pages library of a Communication site with PowerShell.

Activating the hidden feature does not have any effect. Is this possible?

4
  • By modern audience target do you mean enabling Enable audience targeting settings which is available under Library Settings -> Audience Targeting Settings? and by enabling this settings "Audience" column will be added to library where you can define list of groups for target audience? Apr 13, 2023 at 10:58
  • @KalpeshVaghela Yes exactly this Apr 13, 2023 at 11:40
  • @RobertLindgren Check if this helps to convert PowerShell for SP online: c-sharpcorner.com/uploadfile/anavijai/… Apr 19, 2023 at 8:09
  • 1
    @GaneshSanap that is for the classic audience targeting I'm afraid. Apr 19, 2023 at 8:29

1 Answer 1

2
+125

I'm not sure it can be done via PowerShell, however it can be achieved via the EnableModernAudienceTargeting method in the PnP Framework (heavily reliant on CSOM). You can find the underlying code for this in ListExtensions.cs

public static void EnableModernAudienceTargeting(this List list)
4
  • Thanks, that looks exactly like what I'm after. Then I just need to convert that csom code to powershell and try it out. I'll let you know if it works Apr 13, 2023 at 12:02
  • Cool, yes you could do that. Alternatively, you could put a PR in to PnP.PowerShell for the Set-PnPList cmdlet. I couldn't find this functionality there when I looked. Apr 13, 2023 at 17:03
  • I was not able to get this to work, trying to convert that code to PS :( Might be something in my conversion that i acting up, but even if all goes through the values are not stored properly in the targeting column (it gets emptied on refresh) Apr 17, 2023 at 9:21
  • might be worth checking the method works in a simple C# application first. There's an odd "to do" in the method, I don't know what it's referring to github.com/pnp/pnpframework/blob/… Apr 17, 2023 at 10:18

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.