[BUG] Add-PnPFieldToContentType throws error 'Column 'XXX' does not exist. It may have been deleted by another user.' #4659
Unanswered
HWielenDHS
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have created different site columns that have to be added to contenttypes in the document libraries of existing SharePoint subsites.
I'm trying to use a PnP PowerShell script for this with the cmdlet 'Add-PnPFieldToContentType'. But whatever I try I always get the error message: 'Column 'XXX' does not exist. It may have been deleted by another user.'
I'm using a Windows 11 PC with PowerShell 7.4.6 en tried different versions of the PnP.PowerShell module up to the most recent version '2.99.90 nightly'.
In my script I first check if the contenttype is available using an 'If'-statement with:
$contentType = Get-PnPContentType -List $libraryName | Where-Object { $_.Name -eq $contentTypeName }
Secondly I check if the column is available in the document library using using an 'If'-statement with:
$column = Get-PnPField -List $libraryName | Where-Object { $_.InternalName -eq $columnName }
When everything checks out I use the following code to add the column to the contenttype:
Add-PnPFieldToContentType -Field $column.InternalName -ContentType $contentType.Name
I have different types of columns: Number, Line of text and Taxonomy but for all of them I get the same error.
For the '-Field' parameter of the Add-PnPFieldToContentType cmdlet I used the properties: 'Title', 'InternalName', 'Id' and the object itself but it makes no difference.
I can add these columns to the contenttype manually in the SharePoint document libraries without any problems.
What am I missing?
Beta Was this translation helpful? Give feedback.
All reactions