Skip to content

Instantly share code, notes, and snippets.

@potat-dev
Last active January 27, 2025 02:50
Show Gist options
  • Save potat-dev/9e20d2096b60a801067fc641512e63c9 to your computer and use it in GitHub Desktop.
Save potat-dev/9e20d2096b60a801067fc641512e63c9 to your computer and use it in GitHub Desktop.
Fix Invalid File Timestamps Powershell Script for Windows
param(
[string]$Path = ".",
[switch]$Recursive
)
$currentDate = Get-Date
$minDate = Get-Date "1980-01-01"
$scriptPath = $MyInvocation.MyCommand.Path
$params = @{
Path = $Path
File = $true
}
if ($Recursive) {
$params.Recurse = $true
}
Get-ChildItem @params | Where-Object {
$_.FullName -ne $scriptPath -and (
$_.LastWriteTime -gt $currentDate -or
$_.LastWriteTime -lt $minDate
)
} | ForEach-Object {
Write-Host "Fix file timestamps: $($_.FullName)"
$_.LastWriteTime = $currentDate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment