Set 'audiences to target' in SharePoint navigation using PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1987956%22%20slang%3D%22en-US%22%3ESet%20'audiences%20to%20target'%20in%20SharePoint%20navigation%20using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1987956%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20using%20PnP%20PowerShell%20to%20create%20SharePoint%20Hub%20navigation%20nodes%20(Add-PnPNavigationNode)%2C%20but%20cannot%20find%20a%20way%20to%20configure%20the%20audience%20targeting%20via%20PowerShell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20this.%26nbsp%3B%20It%20completed%20without%20error%20but%20it%20did%20NOT%20work%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24node%20%3D%20Get-PnPNavigationNode%20-Id%201234%0AGet-PnPProperty%20-ClientObject%20%24node%20-Property%20%22AudienceIds%22%0A%24node.AudienceIds.Add(%223270e13c-1031-42a3-9104-54139a37527a%22)%0A%24node.Update()%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20insight%20would%20be%20greatly%20appreciated!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1987956%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1988190%22%20slang%3D%22en-US%22%3ERe%3A%20Set%20'audiences%20to%20target'%20in%20SharePoint%20navigation%20using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1988190%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F628%22%20target%3D%22_blank%22%3E%40John%20Palmer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20per%20my%20knowledge%2C%20currently%20it%20is%20not%20possible%20to%20set%20audience%20targeting%20groups%20to%20specific%20navigation%20node%20using%20PnP%20PowerShell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20only%20d%3CSPAN%3Eefine%20if%20the%20navigation%20menu%20on%20a%20modern%20site%20should%20be%20enabled%20for%20modern%20audience%20using%26nbsp%3B%3CSTRONG%3E-NavAudienceTargetingEnabled%26nbsp%3B%3C%2FSTRONG%3Eparameter%20for%26nbsp%3B%3CSTRONG%3ESet-PnPWeb%3C%2FSTRONG%3E%20cmdlet.%20Check%20below%20reference%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20title%3D%22Set-PnPWeb%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-pnp%2Fset-pnpweb%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESet-PnPWeb%3C%2FA%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%20%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

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!

2 Replies

@johndpalm 

 

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:

 

Set-PnPWeb 


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.

 

@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.