Mike,

Change your if statement to: If (((Get-Date) - $datdate).Days -gt 2 ) {

The (Get-Date) - $datdate calculation will return the difference as the 
properties of a System.Timespan value, so your if statement is evaluating based 
on the TotalMilliseconds property.

Thank you,

Jeff Juett


From: [email protected] [mailto:[email protected]] On 
Behalf Of Murray, Mike
Sent: Thursday, January 26, 2017 1:01 PM
To: [email protected]
Subject: [mssms] RE: PowerShell help

To clarify, no matter what I follow "-gt" with, it always returns "Old". My 
test machine has defs that are 2 days old, but if I set the number to 5, it 
still says old.

From: Murray, Mike
Sent: Thursday, January 26, 2017 10:56 AM
To: [email protected]<mailto:[email protected]>
Subject: PowerShell help

I'm trying to write a script that will read the SCEP definition date from 
registry, compare it to the current time, and if it's older than 2 days run an 
action. In my code below, it always returns "Old". What am I missing?

$data = Get-ItemProperty "HKLM:\Software\Microsoft\Windows Defender\Signature 
Updates" | Select-Object -ExpandProperty AVSignatureApplied
$time = [DateTime]::FromFileTime( (((((($data[7]*256 + $data[6])*256 + 
$data[5])*256 + $data[4])*256 + $data[3])*256 + $data[2])*256 + $data[1])*256 + 
$data[0])
$datdate = Get-Date $time
Write-Host $datdate

if ((Get-Date) - $datdate -gt 2) {
Write-Host "Old"
}else {
Write-Host "New"
}



Best Regards,

Mike Murray
Desktop Engineer/IT Consultant - IT Support Services
California State University, Chico
530.898.4357
[email protected]<mailto:[email protected]>

Remember, Chico State will NEVER ask you for your password via email!
For more information about recognizing phishing scam emails go to: 
http://www.csuchico.edu/isec/basics/spam-and-phishing.shtml





Reply via email to