mardi 10 avril 2018

powershell less than statement not printing correct output

I am writing a script that is supposed to be notify me if the expiry-epoch time of a certificate is within 30 days of expiration. However it is just printing the output of all of the files not just the ones that match the if statement. The example I am using is using the below values and I am looking to print the output of $d since $d contains the filename:

PS C:\scripts> $certtime 1560350005

PS C:\scripts> $epochtime 1520858749

$c = Get-Date (Get-Date).ToUniversalTime() -UFormat %s
$epochseconds=[math]::Round($c)
$d = get-childitem C:\scripts\PALO\* -recurse | Select-String -pattern 
"expiry-epoch"
$e=$d -split "epoch"
$certtime=$e[1]
$epochtime = $epochseconds - 2505600

ForEach ($i in $d){
If ($certtime -le $epochtime) {
Write-Output $i
}
}

Aucun commentaire:

Enregistrer un commentaire