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?
You can edit site column properties such as name, group, column type, etc in SharePoint Online by following below steps:
SharePoint Online: Set Site Column Properties using PowerShell CSOM
Here is the PowerShell to update field in SharePoint Online:
Update Site Column Properties using PnP PowerShell
How to Edit a Site Column in SharePoint Online?
You can edit site column properties such as name, group, column type, etc in SharePoint Online by following below steps:
- Navigate to the SharePoint Online site where the site column was created.
- Click on Settings Gear >> Site Settings
- On the Site Settings page, Click on "Site Columns" link under "Web Designer Galleries" group
- On the Site Columns page, click the name of the site column to be edited.
- 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.
- Click the OK button to save the changes.
SharePoint Online: Set Site Column Properties using PowerShell CSOM
Here is the PowerShell to update 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://crescenttech.sharepoint.com" -ColumnName "ProjectName"
Update Site Column Properties using PnP PowerShell
#Config Variables $SiteURL = "https://crescenttech.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.
After running this script getting below error
ReplyDeleteAdd-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.
Make sure you downloaded & installed the SharePoint Online SDK from https://www.microsoft.com/en-us/download/details.aspx?id=42038. In case you installed it in different location, set the path accordingly in the script!
Deletehow to update the managed metadata column? I want to map a termset to the field
ReplyDelete