January 25, 2018

Disable friendly formatting on date columns on SharePoint site collection

Problem

After migrating content to SharePoint 2016, all date columns were in Friendly display format. I needed a neat way to update them across the site collection using PowerShell, but all scripts that attempted to modify the FriendlyDisplayFormat property of a column had some issues.

This one on Social Technet didn’t work as our site wasn’t in English, nor did this or this. Some looked alright, but threw error “The property 'FriendlyDisplayFormat' cannot be found on this object. Verify that the property exists and can be set.

Solution

$WebCollection = Get-SPSite "<SITEURL>" -Limit All | Get-SPWeb -Limit All
 
foreach($web in $WebCollection)
{
     Write-Host "Connected to "$web.Title -ForegroundColor Yellow

    $lists = $web.Lists
 
     foreach($list in @($lists))
     {
         Write-Host "Connected to ...$list" -ForegroundColor Yellow
        
         foreach($field in @($list.Fields))
         {      
             $column = $list.Fields.GetFieldByInternalName($field.InternalName)
       
             if($column.Type -eq "DateTime")
             {                  
                 Write-Host "Connected to ......"$column.Title -ForegroundColor Yellow
                 $column.FriendlyDisplayFormat = 1
                 $column.update()               
             }
         }
     }

    $web.Dispose()
}

No comments:

Post a Comment