Forum Discussion
MrMartinITPro
Sep 15, 2023Copper Contributor
Date comparison does not work
I am attempting to write a file detection script, but PowerShell doesn't seem to recognize that the file dates are equal. Here's what I'm experiencing: PS C:\> $FileDate = Get-Date -Date "2023-0...
MrMartinITPro
Sep 15, 2023Copper Contributor
Found the problem. Here's the fix:
$TestDate = (Get-Date -Date '2023-05-08T11:00:31').DateTime
$FileDate = ((Get-Item '%redacted%').LastWriteTime).DateTime
if ($FileDate -eq $TestDate) {
Write-Host "Detected"
Exit 0
}
else {
Write-Host "Not detected"
Exit 1
}