Resetting Time Stamps via PowerShell

Sometimes when migrating a server or otherwise touching files on a system, the time stamps tend to get modified. (That is, after all, what they're there for).

However, in some situations, this is a sensitive field and some users may have to change they way they work if they sort by last modified in Windows Explorer.

As with most things PowerShell, Ed Wilson, The Scripting Guy, has us covered.

Function Set-FileTimeStamps {
# Taken from

 Param (



    [datetime]$date = (Get-Date))

    Get-ChildItem -Path $path |

    ForEach-Object {

     $_.CreationTime = $creationtime

     $_.LastAccessTime = $accesstime

     $_.LastWriteTime = $modificationtime }

} #end function Set-FileTimeStamps

# Now, we can pass in a $newfilename after we've copied/moved/otherwise touched the file

    #Fix the timestamps
    Set-FileTimeStamps -path $newfilename


Popular Posts