Search code examples
powershellsharepointsharepoint-2016

Create Publishing HTML Site Column using PnPPowershell SP2016


I'm trying to create a sharepoint 2016 site column using PnP powershell.

when I create a single line of text using the command below it works:

 Add-PnPField -DisplayName "column1" -InternalName "column1" -Group "PnPGroup" -Type Text

But I can't create a "Publishing HTML" column using this command :

 Add-PnPField -DisplayName "htmlcolumn" -InternalName "htmlcolumn" -Group "PnPGroup" -Type HTML

Can you tell me which is the appropriate type to create a "Publishing HTML" column ?

Thanks for the help.


Solution

  • You can use Add-PnPFieldFromXml to add the field as below:

    $guid = New-Guid
    $xml = '<Field Type="HTML" Name="htmlcolumn" DisplayName="htmlcolumn" Group="PnPGroup" StaticName="htmlcolumn" RichText="TRUE" ID="{'+$guid.Guid+'}" RichTextMode="FullHtml" />'
    
    Add-PnPFieldFromXml -FieldXml $xml
    

    After that, you can see in the site columns as:

    enter image description here

    Reference - Add-PnPFieldFromXml