jeudi 12 avril 2018

POWERSHELL ERRORS OUT IF STRING IS NOT FOUND

I am having an issue with a script that is supposed to print out the output if the expiry-epoch of a certificate is within 30 days of the present date. However I found out that if the expiry-epoch string is now found then I get an error message "Cannot index into array" which messes up my output. Please let me know how I can run this script on only files containing the expiry-epoch string

$c = Get-Date (Get-Date).ToUniversalTime() -UFormat %s
$epochroundedtimes=[math]::Round($c)
$epochtimes=$epochroundedtimes + 2592000
Get-ChildItem -Path "C:\scripts\PALO\" -File -Recurse | 
ForEach-Object {$epochtimes } {
$certexp = ([double]($_ | Select-String -pattern "expiry-epoch\         
(\d+)$").Matches.Groups[1].Value)
if($certexp -le $epochtimes)
{
$_.FullName
}
}

Aucun commentaire:

Enregistrer un commentaire