Compare creation dates of two files in Powershell

Hi, I've created a script that compares two files in different directories. The aim of the script is, it searches a network location directory and compares it to a local directory, if the file in the network location is newer ("going by date created") than the one stored locally. It copies it into the local directory. Here is my code

$source = import-csv -Path "c:\network.csv" 
$destination = import-csv -Path "c:\local.csv"

$output = @()
forEach ($row in $source) {      
    $result = $destination | Where-Object {$row.Name -eq $_.Name}  

    if ($row.CreationTime -gt $result.CreationTime) { 
        write-host "Found Change"
        write-host  $row.Name, $row.CreationTime
        write-host  $result.Name, $result.CreationTime
        $output += New-object PSObject -property @{  
            FileName = $row.Name  
            CreationTime = $row.CreationTime
        }
    }
}  

$output | select-object FileName | Export-Csv -Path C:\Changes.csv -NoTypeInformation
$NewVersions = import-csv -Path "C:\changes.csv" 
forEach ($row in $NewVersions)
{
    $filename = $row.FileName
}
The problem is that, it seems to be comparing the 2 creation dates as different times. How would I alter this code to compare the dates created not the times?


August 19th, 2015 12:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics