kwizcom banner advertisement

SharePoint Online: Set List Field Settings using PowerShell

Requirement: Update SharePoint Online List Field Settings using PowerShell

PowerShell to Set Field Settings in SharePoint Online List:
#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"

#Set Config Parameters
$SiteURL="https://crescent.sharepoint.com/sites/projects"
$ListName="Projects"
$FieldName="HeadCount" #Internal Name

#Get Credentials to connect
$Cred= Get-Credential

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Get the List
$List=$Ctx.Web.Lists.GetByTitle($ListName)

#Get the List Field
$Field=$List.Fields.GetByInternalNameOrTitle($FieldInternalName)
$Ctx.Load($Field)
$Ctx.ExecuteQuery()

#Set List Field Settings
$Field.Title= "Total Resources"
$Field.Description = "Number of Resources working on the Project"

#set default value
$Field.DefaultValue = "10"

$Field.EnforceUniqueValues = $False

#set field hidden
$Field.Hidden = $False
$Field.Sealed = $False

#set field required
$Field.Required = $True
$Field.FieldTypeKind = "Text"
$Field.Indexed = $False

#set field read only
$Field.ReadOnlyField = $False
$Field.Group = "Custom Columns"
#$Field.JSLink
#$Field.SchemaXML
$Field.ValidationFormula = ""
$Field.ValidationMessage = ""

#Apply changes
$Field.Update()
$Ctx.ExecuteQuery()

Write-host "Field Settings Updated!"
SharePoint Online: Set List Field Settings using PowerShell SharePoint Online: Set List Field Settings using PowerShell Reviewed by Salaudeen Rajack on July 01, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.