Different Ways To Create A Single Line Of Text Column In SharePoint Using PnP PowerShell

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.
  1. PS:> $cred = Get-Credential  
  2. PS:> Connect-PnPOnline -Url https://<tenant>.sharepoint.com -Credential $cred  
Add Single Line of Text Column to List
The following command adds the Text field to the Test List.
  1. 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
  1. 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
  1. PS:> $field = Add-PnPField -DisplayName 'Text Field' -InternalName 'TextField' -Type Text  
  2. 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
  1. PS:> $guid = New-Guid  
  2. PS:> $xml = '<Field Type="Text" Name="TextField2" DisplayName="Text Field 2" ID="                       {'+$guid.Guid+'}" Group="PnP Columns"/>'  
  3. 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. 
  1. PS:> $guid = New-Guid  
  2. PS:> $xml = '<Field Type="Text" Name="TextField2" DisplayName="Text Field 2" ID="{'+ $guid.Guid +'}" Group="PnP Columns"/>'  
  3. 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.
  1. PS:> $guid = New-Guid  
  2. PS:> $xml = '<Field Type="Text" Name="TextField2" DisplayName="Text Field 2" ID="{'+ $guid.Guid +'}" Group="PnP Columns"/>'  
  3. Ps:> $field = Add-PnPFieldFromXml -FieldXml $xml -List 'Test List'  
  4. 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
  1. PS:> Add-PnPField -DisplayName 'Text Field' -InternalName 'TextField' -Type Text -List 'Test List' -Required $true