- CreationTime and CreationTimeUtc - the date/time that the file was created (in local time and UTC)
- LastAccessTime and LastAccessTimeUtc - the date/time that the file was last accessed
- LastWriteTime and LastWriteTimeUtc - the date/time that the file was last written
These properties allow you to check a file (or for that matter a folder) for when it was created and when it was last written to and read from. This is very useful to help IT Professionals to discover files that are underused and may be candidates for deletion. To cater for files being accessed in different time zones, the UTC variants provide time-zone proof times for comparison.
One challenge is that you may wish to change these times. There is no cmdlet that can change these times directly. Fortunately, there is a simple bit of PowerShell magic. Assume you have a file for which you wish to change date/times.
Here is you can do it:
PSH [C:\Foo]: Remove-Item -Path C:\Foo\Foo.xxx -ea 0PSH [C:\Foo]: "FOO" | Out-File -Path C:\Foo\Foo.xxxPSH [C:\Foo]: # Find file and displayPSH [C:\Foo]: $File = Get-ChildItem -Path c:\foo\Foo.xxxPSH [C:\Foo]: $File| Format-List -Property name,*time*Name : Foo.xxxCreationTime : 11/12/2020 10:09:57LastAccessTime : 11/12/2020 10:09:57LastAccessTimeUtc : 11/12/2020 10:09:57LastWriteTime : 11/12/2020 10:09:57LastWriteTimeUtc : 11/12/2020 10:09:57PSH [C:\Foo]: # Get new datePSH [C:\Foo]: $NewDate = Get-Date -Date '14/08/1950'PSH [C:\Foo]: # Change the datePSH [C:\Foo]: $File.CreationTime = $NewDatePSH [C:\Foo]: $File.CreationTimeUTC = $NewDatePSH [C:\Foo]: $File.LastAccessTime = $NewDatePSH [C:\Foo]: $File.LastACcessTimeUTC = $NewDatePSH [C:\Foo]: $File.LastWriteTime = $NewDatePSH [C:\Foo]: $File.LastWriteTimeUTC = $NewDatePSH [C:\Foo]: # Recheck file to see changed date/timePSH [C:\Foo]: $File = Get-ChildItem -Path C:\Foo\Foo.xxxPSH [C:\Foo]: $File| Format-List -Property Name,*Time*Name : Foo.xxxCreationTime : 14/08/1950 01:00:00CreationTimeUtc : 14/08/1950 00:00:00LastAccessTime : 14/08/1950 01:00:00LastAccessTimeUtc : 14/08/1950 00:00:00LastWriteTime : 14/08/1950 01:00:00LastWriteTimeUtc : 14/08/1950 00:00:00