Здравствуйте. У меня есть следующий скрипт, который позволяет мне получить информацию о сертификате и сохранить их в файле CSV
. Я хочу исключить некоторые сведения о сертификате из файла CSV
, которые являются сертификатами, у которых осталось более 3650 дней. до истечения срока действия
Вот мой сценарий
$StartDate = Get-Date
$CertPath = 'Cert:\LocalMachine\'
$CertsDetail = Get-ChildItem -Path $CertPath -Recurse |
Where-Object { $_.PsIsContainer -ne $true } | ForEach-Object {
$DaysLeft = (New-TimeSpan -Start $StartDate -End $_.NotAfter).Days
if ($DaysLeft -lt 1) {
$Under30 = $true
$Expired = $true
$Text = "The Certificate is expired"
}
elseif ($DaysLeft -lt 30) {
$Under30 = $true
$Expired = $false
$Text = "The Certificate is but valid about to expire"
}
else {
$Under30 = $false
$Expired = $false
$Text = "The Certificate is still valid and not going soon to expire"
}
$FinalDate = get-date $_.NotAfter -Format 'dd/MM/yyyy hh:mm'
[PSCustomObject]@{
Text = $Text
Subject = $_.Subject
ExpireDate = $FinalDate
DaysRemaining = $DaysLeft
Under30Days = $Under30
Expired = $Expired
}
}
$CertsDetail | Export-Csv -NoTypeInformation -Path'C:\SECnology\Data\Utilities\Certificate_State.csv'