You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a PnP.PowerShell script to updates the "Audience" column under the Site Page content type, so that it is a required field rather than optional?
I tried the below but it doesn't work?
# Get Context
$clientContext = Get-PnPContext
# Give target content type name over here
$targetContentType = Get-PnPContentType -Identity "Site Page"
# Load target content type and content type fields
$clientContext.Load($targetContentType)
$clientContext.Load($targetContentType.Fields)
$clientContext.ExecuteQuery()
# Get required field from the target content type
# Mention field internal name or display name over here
$targetField = $targetContentType.Fields.GetByInternalNameOrTitle("Audience")
$clientContext.Load($targetField)
$clientContext.ExecuteQuery()
# Make content type field required
$targetContentType.FieldLinks.GetById($targetField.Id).Required = $true
# Update(UpdateChildren – bool), this value indicates whether the children content type(inheriting from this Content Type) needs to be updated. 0 = False, 1 = True
$targetContentType.Update(0)
$clientContext.ExecuteQuery()
The script cannot find the field "Audience" even if I use the "_ModernAudienceTargetUserField" name???
Exception calling "ExecuteQuery" with "0" argument(s): "Column 'Audience' does not exist. It may have been deleted by another user."
MethodException:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
I am trying to create a PnP.PowerShell script to updates the "Audience" column under the Site Page content type, so that it is a required field rather than optional?
I tried the below but it doesn't work?
The script cannot find the field "Audience" even if I use the "_ModernAudienceTargetUserField" name???
Exception calling "ExecuteQuery" with "0" argument(s): "Column 'Audience' does not exist. It may have been deleted by another user."
MethodException:
Beta Was this translation helpful? Give feedback.
All reactions