Blog‎ > ‎IT‎ > ‎

Powershell Rename File with TimeStamp

posted Apr 18, 2016, 9:30 PM by Jake Vosloo
This script takes a file and renames it to include the last write time stamp in the file name.


if (Test-Path $LogFile) {
  $LogFileTimestamp = ([datetime](Get-ItemProperty -Path $LogFile -Name lastwritetime).lastwritetime).ToString("yyyyMMddTHH.mm.sszz")
  $LogBackupfile = $LogFile.Replace(".", "_$LogFileTimestamp.")
  Rename-Item $LogFile $LogBackupfile
}


Comments