Last active
January 27, 2025 02:50
-
-
Save potat-dev/9e20d2096b60a801067fc641512e63c9 to your computer and use it in GitHub Desktop.
Fix Invalid File Timestamps Powershell Script for Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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