By using PnPPowerShell, we can create a column by specifying the Column Name or field xml as a parameter value to the PowerShell command Add-PnPField and Add-PnPFieldXml respectively.
I have provided the examples below for creating the single line of text column to the Web, List and ContentType using the PnPField Commands, Before running the add-PnPField commands, we have to connect the SharePoint site using Connect-PnPOnline command.
- PS:> $cred = Get-Credential
- PS:> Connect-PnPOnline -Url https:
Add Single Line of Text Column to List
The following command adds the Text field to the Test List.
- PS:> Add-PnPField -DisplayName 'Text Field' -InternalName 'TextField' -Type Text -List 'Test List'
Add Single Line of Text Column to Web
The followng command is used to add the Text Field column as a Site Column
- PS:> Add-PnPField -DisplayName 'Text Field' -InternalName 'TextField' -Type Text
Add Single Line of Text Column to ContentType
The following command adds the "Text field" column as a site column and then its added to the Site ContentType
- PS:> $field = Add-PnPField -DisplayName 'Text Field' -InternalName 'TextField' -Type Text
- PS:> Add-PnPFieldToContentType -Field $field -ContentType 'Content Type Name'
Add Single Line of Text Column to Web using Xml
The following command adds the "Text Field 2" column as a site column based on the xml
- PS:> $guid = New-Guid
- PS:> $xml = '<Field Type="Text" Name="TextField2" DisplayName="Text Field 2" ID=" {'+$guid.Guid+'}" Group="PnP Columns"/>'
- PS:> Add-PnPFieldFromXml -FieldXml $xml
Add Single Line of Text Column to List using Xml
The following command adds the "Text Field 2" column to the Test List based on the xml.
- PS:> $guid = New-Guid
- PS:> $xml = '<Field Type="Text" Name="TextField2" DisplayName="Text Field 2" ID="{'+ $guid.Guid +'}" Group="PnP Columns"/>'
- PS:> Add-PnPFieldFromXml -FieldXml $xml -List 'Test List'
Add Single Line of Text Column to ContentType using Xml
The following command adds the "Text Field 2" column as a site column based on the xml. And then add that field to the content type.
- PS:> $guid = New-Guid
- PS:> $xml = '<Field Type="Text" Name="TextField2" DisplayName="Text Field 2" ID="{'+ $guid.Guid +'}" Group="PnP Columns"/>'
- Ps:> $field = Add-PnPFieldFromXml -FieldXml $xml -List 'Test List'
- PS:> Add-PnPFieldToContentType -Field $field -ContentType 'Content Type Name'
Add Single Line of Text column as a Required Column
The following command adds the field as a required column to the Test List
- PS:> Add-PnPField -DisplayName 'Text Field' -InternalName 'TextField' -Type Text -List 'Test List' -Required $true