Q:

How to compare Last. Write. Time using Powershell

I wanted to write script which will merge files to one, IF they were modified later then the one which should be a destination.  My script looks like this:
Function UnifyConfigs { param ( $destination = "C:\temp\all.txt", [Parameter()] $files )

foreach ($config in $files) {
    If((Get-ChildItem $config ).LastWriteTime -gt (Get-Item $destination).LastWriteTime)
    {
        Clear-Content -path $destination
        Set-Content -path $destination -value (Get-Content $config) 
    }
    else {
        break
    }  
}
}

My main problem is that $destination file is modified ALWAYS .  As far as I understand it should be changed only if modification date of $config is greater than modification date of $destination.  But now, it is overwritten each time I run script.  What is wrong? 

A:

$destination as defined in your param block is a string - you need to resolve the corresponding item in the file system provider to get to the LastWriteTime value - here using Get-Item:
if((Get-Item $config).LastWriteTime -gt (Get-Item $destination).LastWriteTime)
{
    # ...
}

