I am using a PowerShell script to validate file dates on remote production servers. The check outputs a code number to our deployment tool to report either a passing or failing result to indicate if the file is correct or not.
This works, however the only problem I have is that I cannot get the following script to work with an -eq
and have instead used a -gt
and put the file date in the script one day less than the actual file date. For instance, 11/17/2014 in the script to check a 11/18/2014 file.
$FileExe= Get-ChildItem "C:\filepath\file.exe" |
Where-Object {$_.LastWriteTime -gt "11/17/2014"} | Out-String
if($FileExe){Write-Host '0'} else{Write-Host '4';Exit 4}
Assuming the file is the correct 11/18/2014 file, this will output a 0, indicating it passes. If not, then it outputs a 4 indicating the wrong file is in place at which point I can go in and fix it.
If I change the -gt
to an -eq
and change the date in the script to match the actual file date (11/18/2014 in this example), the script fails and outputs the error code. This is despite the fact the file date and date in the script is correct.
At this point, I am at a loss. Am I doing something wrong with my script, or is there a better way to do what I am trying to do here that will allow an -eq
?