vendredi 26 juin 2015

Nested IF ELSE condition and logic not working for some reason

Why doesnt ELSE work below? Syntax and flow appears to be correct for conditions. Please dont post an alternate solution without explaining exactly why the logic below doesn't work. Ideally, the least complex example (that's human readable) would greatly be appreciated.

$File = gi "P:\tmp\MKA.theme"
$lastWrite = (get-item $File).LastWriteTime
$timespan = new-timespan -hours 8
$FileLeaseGood = $NULL
if (((get-date) - $lastWrite) -le $timespan) {$FileLeaseGood = $True}

if (Test-Path $File) {
    write-host "File exists!"
    if ($FileLeaseGood) {

        write-host "File exists! and File Lease still good"

    }} else {

        #Why doesn't this else condition work???
        Write-host "This condition is true. But ignored!"


    }

Aucun commentaire:

Enregistrer un commentaire