Tuesday, February 6, 2018

How to Change Modified Date of Document in SharePoint Library using PowerShell

# add pssnapin
Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue

# create objects for site-url, list/library name and file name
$objSiteURL = "http://SHAREPOINT-SITE-URL"
$objListName = "LIBRARY NAME"
$objFileName = "FILE NAME" 

# open the site from web and get the appropriate library
$objWeb = get-SPWeb $objSiteURL
$objList = $objWeb.lists[$objListName

# get the item using file name
$item = $objList.Folders | ? {$_.Name -eq $objFileName

# display the modified date before update operation
Write-Output ("BEFORE: Item created by {0} on {1}" -f $item["Author"].tostring(), $item["Modified"] )

# assign any custom date
$item["Modified"] = $dateToStore

# update Item
$item.UpdateOverwriteVersion()

# display the modified date after update operation
Write-Output ("AFTER: Item created by {0} on {1}" -f $item["Author"].tostring(), $item["Modified"] )

No comments:

Post a Comment