Dec 14 2020 07:33 PM
I'm using PnP PowerShell to create SharePoint Hub navigation nodes (Add-PnPNavigationNode), but cannot find a way to configure the audience targeting via PowerShell.
I tried this. It completed without error but it did NOT work:
$node = Get-PnPNavigationNode -Id 1234
Get-PnPProperty -ClientObject $node -Property "AudienceIds"
$node.AudienceIds.Add("3270e13c-1031-42a3-9104-54139a37527a")
$node.Update()
Any insight would be greatly appreciated!
Dec 14 2020 11:19 PM
As per my knowledge, currently it is not possible to set audience targeting groups to specific navigation node using PnP PowerShell.
You can only define if the navigation menu on a modern site should be enabled for modern audience using -NavAudienceTargetingEnabled parameter for Set-PnPWeb cmdlet. Check below reference:
Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Dec 15 2020 09:09 AM
@ganeshsanap
Thanks! I'm aware of how to enable audience targeting through PowerShell. I need to do the next step which is to add groups to the 'audiences to target' field.
Feb 23 2021 03:26 AM
Hi @johndpalm Is there any update on this? Could you please share the code to achieve this?
May 13 2021 08:12 AM
Apr 07 2022 01:14 AM
AudienceIds are a list of GUIDs, so try this one:
$audienceList = New-Object System.Collections.Generic.List[guid]
$audienceList.add([System.guid]::New(("YOURGROUPID")))
$node.AudienceIds = $audienceList
$node.Update()
Invoke-PnPQuery
Oct 13 2022 01:01 PM
I tried your code and when I view the SharePoint site I can see that it added the audience to my QuickLaunch link but it doesn't seem to have any affect. I added an audience (office 365 group that I am not a part of) to the link but I can still see the link.
Here is an example of what I'm referring to. I'm not part of this audience but the DMA Support link is still visible to me. When I add the audience manually through the SharePoint UI it works fine. The link is hidden from me. It just doesn't work when I do it from PnP PowerShell.