Skip to content

Instantly share code, notes, and snippets.

@Rugby-Ball
Last active July 31, 2023 02:24
Show Gist options
  • Save Rugby-Ball/eda56e4d2676a6abfc98f15f9583ceb4 to your computer and use it in GitHub Desktop.
Save Rugby-Ball/eda56e4d2676a6abfc98f15f9583ceb4 to your computer and use it in GitHub Desktop.
Pull an Inventory of AWS Certificate Manager (ACM) that are `ISSUED` and the AWS Service using them across all AWS regions. Export to a CSV file. #Utility #Inventory #Public #AWS #AWS_ACM
# ACM-Service-list-with-ACM-InUse.ps1
<#
Description: Pull an Inventory of AWS Certificate Manager (ACM) that are `ISSUED` and the AWS Service using them across all AWS regions. Export to a CSV file.
Written: Ed Walsh
PowerShell.Core tested: Yes
MS-Graph: No
Version: 1.3
Create Date: 7/25/2023
Revised Date: 7/28/2023
#>
import-module -name AWSpowershell
$timestamp = get-date -format yyyyMMddHHmmss
$subfolder = if (($PSVersionTable.PSEdition) -eq "Core") { if ( $True -eq $iswindows ) { "\Documents\" } Else { "" } } Else { "\Documents\" }
$mydocuments = $home + $subfolder
$fileName = "ACM-Service-list-with-ACM-InUse-" + [string]$timestamp + ".csv"
$filePath = Join-Path $mydocuments $fileName
$region = ""
$asof = Get-Date -format "MM-dd-yyyy hh:mm tt"
$out = @()
Get-EC2Region -RegionToCall us-east-1 <# -RegionToCall used because of https://github.com/aws/aws-tools-for-powershell/issues/46 #> | Foreach-Object {
$region = $_.RegionName
$count = (Get-ACMCertificateList -Region $region -CertificateStatus "ISSUED" -ErrorAction SilentlyContinue | Measure-Object ).count
if ($count -gt 0) {
$alldata = (Get-ACMCertificateList -Region $region -CertificateStatus "ISSUED").CertificateArn | Get-ACMCertificateDetail -Region $region
ForEach ($data in $alldata) {
foreach ($x in $data.inuseby) {
$out += [PSCustomObject]@{
"As-Of" = [String]$asof
"AWS-Acct_Number" = "`"$([STRING]$x.split(':')[4])`"" #Added the excaped " so that when you open csv file in Excel doesnt show as a mathatical function
Region = $region
Service = $x.split(':')[2]
ARN = $x
"Cert-ARN" = $data.CertificateArn
"Cert-DomainName" = $data.DomainName
"Cert-Subject" = $data.Subject
"Cert-SAN" = $data.SubjectAlternativeNames -join ';'
"Renewable-Eligibility" = $data.RenewalEligibility
"Expire-Date" = $data.NotAfter
"Start-Date" = $data.NotBefore
"ACM-Type" = $data.Type
}
}
}
}
}
$out | sort-object Expire-date | Export-Csv -NoTypeInformation $filePath
Write-Output "Exported to: $filePath"
Write-Output "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|||||||////////////////////////////////////"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment