Enable audience targeting in Modern site pages library using pnp PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1211188%22%20slang%3D%22en-US%22%3EEnable%20audience%20targeting%20in%20Modern%20site%20pages%20library%20using%20pnp%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1211188%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20am%20using%20below%20command%20to%20enable%20audience%20targeting%20on%20site%20pages%20library%20in%20Modern%20communication%20site.%20It%20adds%20a%20column%20named%26nbsp%3BTarget%20Audiences%20of%20type%20Audience%20Targeting.%20But%20I%20am%20not%20sure%20if%20it%20enables%20audience%20targeting%20for%20library%20since%20column%20is%20not%20visible%20in%20page%20properties%20and%20I%20do%20not%20see%20toggle%20switched%20to%20enabled%20in%20library%20settings.%3C%2FP%3E%3CP%3EAdd-PnPFieldFromXml%20'%3CFIELD%20id%3D%22%26quot%3B%7B61cbb965-1e04-4273-b658-eedaa662f48d%7D%26quot%3B%22%20type%3D%22%26quot%3BTargetTo%26quot%3B%22%20name%3D%22%26quot%3BTarget_x0020_Audiences%26quot%3B%22%20staticname%3D%22%26quot%3BTarget_x0020_Audiences%26quot%3B%22%20displayname%3D%22%26quot%3BTarget%22%20audiences%3D%22%22%3E%3C%2FFIELD%3E'%20-List%20SitePages%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20please%20help%20with%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3EAkash%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1211188%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAudience%20Targeting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%20Modern%20Experience%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1215303%22%20slang%3D%22en-US%22%3ERe%3A%20Enable%20audience%20targeting%20in%20Modern%20site%20pages%20library%20using%20pnp%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1215303%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3EIf%20you%20want%20to%20target%20the%20pages%20for%20specific%20users%2C%20please%20set%20the%20permissions%20for%20those%20users%20so%20that%20they%20won't%20be%20able%20to%20see%20or%20access%20the%20page%20from%20the%20pages%20library.%20Enabling%20the%20Target%20Audience%20is%20fine%20but%20to%20edit%20the%20properties%20of%20the%20page%2C%20you%20have%20to%20add%20the%20field%20to%20the%20default%20content%20type%20of%20the%20Pages%20library%2C%20these%20are%20not%20recommended.%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,

I am using below command to enable audience targeting on site pages library in Modern communication site. It adds a column named Target Audiences of type Audience Targeting. But I am not sure if it enables audience targeting for library since column is not visible in page properties and I do not see toggle switched to enabled in library settings.

Add-PnPFieldFromXml '<Field ID="{61cbb965-1e04-4273-b658-eedaa662f48d}" Type="TargetTo" Name="Target_x0020_Audiences" StaticName="Target_x0020_Audiences" DisplayName="Target Audiences" />' -List SitePages

 

Could you please help with this?

 

Thanks in advance.

 

Regards,

Akash

 

1 Reply
Highlighted
Hi,
If you want to target the pages for specific users, please set the permissions for those users so that they won't be able to see or access the page from the pages library. Enabling the Target Audience is fine but to edit the properties of the page, you have to add the field to the default content type of the Pages library, these are not recommended.