Tuesday, 15 July 2014

Match dates with different formats in Powershell -



Match dates with different formats in Powershell -

i trying match boot time file modified date within couple minutes of each other.

i can info don't know how computations. here get:

ps e:\> $disk=gci -attributes hidden e:\filename.ext | select lastwritetime ps e:\> $disk lastwritetime ------------- 6/23/2014 12:55:48 pm ps e:\> $boottime=get-ciminstance -classname win32_operatingsystem | select lastly bootuptime ps e:\> $boottime lastbootuptime -------------- 6/23/2014 12:55:39 pm

what looking in english language way "if lastwritetime within 5 minutes of lastboot time, good. if not, bad"

how can powershell?

i subtract datetimes , utilize resulting timespan object. also, note using -expandproperty needed bare value select-object.

$disk=gci -attributes hidden e:\filename.ext | select -expandproperty lastwritetime $boottime=get-ciminstance -classname win32_operatingsystem | select -expandproperty lastbootuptime if(($disk-$boottime).totalminutes -lt 5){ "all good" }

powershell powershell-v2.0

No comments:

Post a Comment