Update Default Value of a Date and Time field

Ohhh how handy can PowerShell be!

I needed to change the default value of a Date and Time field for several hundred sites. PowerShell allowed me to update the field on all of my SharePoint sites in a matter of seconds.

#add-pssnapin microsoft.sharepoint.powershell

$spsite=[Microsoft.SharePoint.SPSite]("http://sharepointed.com/customers/")

foreach ($web in $spsite.AllWebs) 

{
    Write-Host $web.name
    
    $List = "List or Library"
    $OpenList = $web.Lists[$List]

    $Field = $OpenList.Fields["My Date Field"]
	$Field.DefaultValue = "[today]"
    $Field.Update($True)
    
    $web.Dispose()

}
$spsite.Dispose()

Leave a Reply

Your email address will not be published. Required fields are marked *