I'm trying to write a script that will copy a file to a second location, when the file changes. For that I'm using an if statement like this:
if (
(Get-ChildItem C:\folder2\file).LastWriteTimeUtc -ge (Get-ChildItem C:\folder1\file).LastWriteTimeUtc
)
{exit}
else
{#execute}
Right now the files are exactly the same and if I run
(Get-ChildItem C:\folder2\file).LastWriteTimeUtc
the result for both is
Friday, 15. April 2022 23:32:09
My issue is that both LastWriteTimes appear to be the same and the script shouldn't do anything, but it does. And the reason for that is, that even though both values seem to be the same they are not and comparing them with "-eq" returns "False".
I'm using PowerShell 5.1