SharePoint Online: Content Type and Site Column operation with PnP PowerShell

First, you will have to connect to your SharePoint Online Site

Example: Connect to SPO

$siteurl = ""  
Connect-SPOnline -Url $siteurl  
$ctx = Get-SPOContext  

========== Site Columns ==========

Example: Adding a site column

#Adding Text Column
Add-SPOField -DisplayName "Text Column" -InternalName "TextColumn" -Group "Test" -Type Text -Required
#Adding Note Column
Add-SPOField -DisplayName "Note Column" -InternalName "NoteColumn" -Group "Test" -Type Note -Required
#Adding Choice Column
Add-SPOField -DisplayName "Choice Column" -InternalName "ChoiceColumn" -Group "Test" -Type Choice -Choices @("Test Value 1","Test Value 2","etc..")
#Other field types such as: Boolean, Integer, DateTime, Lookup, Number, etc...

Example: Retrieving site column(s)

#Get all site column

#Get single site column
Get-SPOField -identity "TextColumn"

Example: Retrieving site column properties

#Get all site column
$fields = Get-SPOField
foreach(var $field in $fields) {

#Get single site column
$field = Get-SPOField -identity "TextColumn"

========== Content Type ==========

Example: Create Content Type

$parentCT = Get-SPOContentType -Identity Link
Add-SPOContentType -Name "SpecialLink" -Group "Custom" -ParentContentType $parentCT

Example: Associate site column with content type

#By Name
Add-SPOFieldToContentType -Field "TextColumn" -ContentType "SpecialLink"

#By Reference
$field = Get-SPOField -identity "TextColumn"
$parentCT = Get-SPOContentType -Identity "SpecialLink"
Add-SPOFieldToContentType -Field $field -ContentType $parentCT

Example: Deleting Site Column

Remove-SPOField -Identity "TextColumn" -Force

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s