pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
989 stars 662 forks source link

Add new switch parameter "-AddToAllContentTypes" to Add-PnPField to automatically add the new field to all list content types #2909

Closed jackpoz closed 3 years ago

jackpoz commented 4 years ago

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:

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

image

erwinvanhunen commented 3 years ago

Thanks!