user8172425
user8172425

Reputation: 121

Powershell script to get the certificates that are not in use

I need some help with the powershell script to get the certificates that are no longer in use in AWS.

$Result = Get-ACMCertificatelist |Get-ACMCertificateDetail I don't know how to sort after that.

Thanks in advance for your help and time,

Upvotes: 1

Views: 378

Answers (1)

Adam
Adam

Reputation: 4168

Disclaimer: I haven't tested this. I don't use AWS. I wrote this solely from AWS documentation for Get-ACMCertificatelist and Get-ACMCertificateDetail.

$invalid_certificates = @()
$certificates = Get-ACMCertificatelist

foreach ($certificate in $certificates) {
    $certificate_detail = Get-ACMCertificateDetail -CertificateArn $certificate.CertificateArn

    if ( $certificate_detail.InUseBy.Count -eq 0 ) {
         $invalid_certificates += $certificate
    }
}

## List of invalid certificates
Write-Output $invalid_certificates

I don't know what qualifies a certificate as "no longer in use". I'm assuming whatever qualifies that can be found in the certificate properties. You can dial-in what I have here to meet your criteria.

Upvotes: 1

Related Questions