I just want to ask for some guidance/help as to why I am not getting any results when I query the variable for the array I used
Background on what I want to achieve is this. I am trying to gather details for a SSL Certificate that is about to expire. Before I display the total list. I want to first store it in an array and later on after the "IF" statement, that's the time I will display the complete list. My script is below. I am a newbie on scripting. I am not getting any errors but there is no result. Your advice will really be a big help
$DaysBeforeExpiry=90
$Rep = @()
$Expiry = Get-ChildItem -Path cert: -Recurse | Where-Object { $_.PSIsContainer }
ForEach-Object {
$obj = New-Object PSObject
$Daysleft = $Cert.NotAfter - (get-date)
$obj | Add-Member -Membertype NoteProperty -Name "Path" $cert.PSParentPath
$obj | Add-Member -Membertype NoteProperty -Name "Issuer" $cert.Issuer
$obj | Add-Member -Membertype NoteProperty -Name "NotAfter" $cert.NotAfter
$obj | Add-Member -Membertype NoteProperty -Name "DaysLeft" $DaysLeft
foreach ($cert in $Expiry) {
if ($cert.notafter -le (get-date).Adddays($DaysBeforeExpiry) -and $cert.notafter -gt (get-date)) {
$Rep +=$obj
}
}
}
$Rep
Foreach-Objectis meant for pipeline input.