SharePoint Online: Set Site Column Properties using PowerShell

Requirement: Update Properties of a Site Column in SharePoint Online using PowerShell.

How to edit a Site Column in SharePoint Online?

In this blog post, we’ll show you how to update the settings for a site column using PowerShell in SharePoint Online. This can be useful if you need to make changes to a site column’s settings after it has been created, or if you want to automate the process of setting up new site columns. Let’s get started!

You can edit site column properties such as name, group, column type, etc., in SharePoint Online by following the below steps:

  1. Navigate to the SharePoint Online site where the site column was created.
  2. Click on Settings Gear >> Site Settings
  3. On the Site Settings page, click on the “Site Columns” link under the “Web Designer Galleries” group
  4. On the Site Columns page, click the name of the site column to be edited.
  5. On the Edit Site Column page, You can make necessary changes and set whether all list columns based on this site column are to be updated to reflect your changes.
  6. Click the OK button to save the changes.sharepoint online update site column powershell

If the site column name is not clickable, the site column may be created in the parent site. Navigate to the parent site as indicated by the “Source Column” where the site column was created, and then you can edit the site column.

SharePoint Online: Set Site Column Properties using PowerShell CSOM

Here is the PowerShell to update a field in SharePoint Online:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Set-SPOSiteColumn($SiteURL,$ColumnName)
{
    #Setup Credentials to connect
    $Cred = Get-Credential
    $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Cred

        #Check if the site column exists
        $Fields = $Ctx.web.Fields
        $Ctx.Load($Fields)
        $Ctx.ExecuteQuery()
        $FieldNames = $Fields | Select -ExpandProperty InternalName

        #Get the site column from sharepoint online site
        If($FieldNames.Contains($ColumnName))
        {
            #Get the site column
            $SiteColumn = $Fields.GetByInternalNameOrTitle($ColumnName)

            #Update Field Properties
            $Sitecolumn.Required = $True
            $Sitecolumn.Description="Current Status of the Project"
            $SiteColumn.Update()
            #Use: $siteColumn.UpdateAndPushChanges() to push changes to all lists

            $Ctx.ExecuteQuery()
            Write-host -f Green "Site Column Updated Successfully!"
        }
        else
        {
            Write-host -f Yellow "Site Column doesn't Exist!"
        }
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}

#Call the Function with Site URL and Internal Name of the Field
Set-SPOSiteColumn -SiteURL "https://Crescent.sharepoint.com" -ColumnName "ProjectName"

Update Site Column Properties using PnP PowerShell

To update a site column’s settings, use this PowerShell:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$FieldName = "ProjectStatus" #Internal Name

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
    
    #Set Site Column Properties
    Set-PnPField -Identity $FieldName -Values @{Description="Current Status of the Project";Group="Crescent Site Columns V2"}    
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

We also have a -UpdateExistingLists switch to update the site column in all existing Lists.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

3 thoughts on “SharePoint Online: Set Site Column Properties using PowerShell

  • how to update the managed metadata column? I want to map a termset to the field

    Reply
  • After running this script getting below error

    Add-Type : Cannot bind parameter ‘Path’ to the target. Exception setting “Path”: “Cannot find path ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll’ because it does not exist.”

    Downloaded both the packages Client.dll and Client.Runtime.dll then also getting same error. Please help.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *