There is already an answer for doing this with a field name that is unique among lists in a site but I have a field name that is not unique ("Comments") and am trying to figure out how to make the solution linked below specific for a certain SharePoint list.
1 Answer
Here is sample script for your reference.
Add-Type -Path (Resolve-Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")
Function Get-SPOContext([string]$Url,[string]$UserName,$Password)
{
write-host Get-SPOContext
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password) #SecurePassword
return $Context
}
$UserName = "[email protected]"
$Password = Read-Host -Prompt "Enter password" -AsSecureString
$Url = "https://xxx.sharepoint.com/sites/Developer"
$listTitle="MyList"
$FieldName="Comment"
$Context = Get-SPOContext -Url $Url -UserName $UserName -Password $Password
$List = $Context.Web.Lists.GetByTitle($ListTitle)
$Context.Load($List)
$Context.ExecuteQuery()
#Retrieve field
$field = $List.Fields.GetByInternalNameOrTitle($FieldName)
$Context.Load($field)
$Context.ExecuteQuery()
$field.SetShowInEditForm($false)
$field.UpdateAndPushChanges($true)
$Context.ExecuteQuery()
write-host Done
-
Thanks so much for your help! That worked great! I'm still really new to PowerShell and the SharePoint Object Model. I need to do some studying up on it when I get a chance.– BenGradyCommented Dec 4, 2017 at 16:32