0

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.

Hide column from Edit form in SharePoint Online

0

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 = "lee@xxx.onmicrosoft.com"
$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. – BenGrady Dec 4 '17 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.