Add new switch parameter "-AddToAllContentTypes" to Add-PnPField to automatically add the new field to all list content types.
ParameterSet_ADDFIELDTOLIST and ParameterSet_ADDFIELDBYXMLTOLIST are supported.
Example:
Connect-PnPOnline $siteUrl
#create list with 3 content types
$list = New-PnPList -Title "AddToAllContentTypes" -Template GenericList
Set-PnPList -Identity $list -EnableContentType $true
Add-PnPContentType -Name "CT1"
Add-PnPContentType -Name "CT2"
Add-PnPContentType -Name "CT3"
Add-PnPContentTypeToList -List $list -ContentType "CT1"
Add-PnPContentTypeToList -List $list -ContentType "CT2"
Add-PnPContentTypeToList -List $list -ContentType "CT3"
#add the field to all 3 content types
Add-PnPField -List $list -DisplayName "FieldForAllCTs" -InternalName "FieldForAllCTsInternal" -AddToDefaultView -Type Text -AddToAllContentTypes
Type
Related Issues?
Partially fixes https://github.com/pnp/PnP-PowerShell/issues/2535 . https://github.com/pnp/PnP-Sites-Core/pull/2754 in PnP-Sites-Core is required to be merged first.
What is in this Pull Request ?
Add new switch parameter "-AddToAllContentTypes" to Add-PnPField to automatically add the new field to all list content types. ParameterSet_ADDFIELDTOLIST and ParameterSet_ADDFIELDBYXMLTOLIST are supported.
Example: