question

ComputerHabit-1849 avatar image
0 Votes"
ComputerHabit-1849 asked EmilyDu-MSFT edited

Add Field to Sharepoint List Content Type using PNP

I'm trying to add a field to an existing list content type using PowerShell SharePoint PNP.

Non of the add-pnpfield commands have a list switch. How do you update a content type in a list?

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered EmilyDu-MSFT commented

@ComputerHabit-1849

When you use following Add-PnPField PowerShell, you will add the column to the default list content type.

 $SiteURL = "https://crescenttech.sharepoint.com"
 $ListName= "Team Projects"
 $ColumnName= "ProjectStartDate" #Internal Name
     
 $Cred = Get-Credential
     
 Try {
     Connect-PnPOnline -Url $SiteURL -Credentials $Cred
         
     Add-PnPField -List $ListName -Field $ColumnName -ErrorAction Stop
     Write-host "Site Column '$ColumnName' Added to List Successfully!" -f Green
 }
 catch {
     write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
 }

For another list content type, add column in it through PnP PowerShell is not available. You could add the column in it manually. Here're steps:

1.Go to list settings -> Content types section -> Select the content type.
123524-11.png
2.Add from existing site or list columns.
123460-12.png

Or you could add a column to the list manually, click "Add to all content types".
123563-13.png


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



11.png (26.8 KiB)
12.png (18.5 KiB)
13.png (27.8 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yeah I specifically need to be able to add the columns as described in the screenshots. I'm working with backup software and attempting restores. It seems the content types don't properly restore and I was hoping to get by just adding the columns.

0 Votes 0 ·

@ComputerHabit-1849

For some columns missing in the content type, I suggest you add them back manually.

0 Votes 0 ·

@ComputerHabit-1849

I’m checking how the things are going on about this issue. If there is any problem with this issue, feel free to let me know.

0 Votes 0 ·
ComputerHabit-1849 avatar image
0 Votes"
ComputerHabit-1849 answered

Still a problem. The issue is after restore the sites content types are not all restored. The lists have the content type in them but they aren't tied to the site content types.

I think the site has some sort of issues as well. I was attempting to use the Sharepoint PNP commands to export the site. The fields will not export.

When I created the site I used SharePoint PNP to create all the content types and metadata. I must have done something wrong or the current pnp export commands just fail.

Currently I working towards replacing some of the metadata in the content types with text boxes instead of lookups. I've been trying use PowerApps but I come up with the limit for lookup columns.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered EmilyDu-MSFT edited

@ComputerHabit-1849

Based on your description, I understand that you want to backup and restore a site collection including some custom content types with lookup columns.

I suggest you use "Save site as a template" to backup and restore the site collection. Please refer this article.


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.