PowerShell AWS: List Certificates

Back to Index

Retrieves a list of ACM Certificates and the domain name for each. You can optionally filter the list to return only the certificates that match the specified status.

Documentation: http://docs.aws.amazon.com/acm/latest/APIReference/API_ListCertificates.html


[Reflection.Assembly]::LoadFile("C:\myAssemblies\ChilkatDotNet2.dll")

$rest = New-Object Chilkat.Rest

#   Provide AWS credentials for the REST call.
$authAws = New-Object Chilkat.AuthAws
$authAws.AccessKey = "AWS_ACCESS_KEY"
$authAws.SecretKey = "AWS_SECRET_KEY"
$authAws.ServiceName = "acm"
$authAws.Region = "us-east-1"
$rest.SetAuthAws($authAws)

$success = $rest.Connect("acm.us-east-1.amazonaws.com",443,$true,$true)
if ($success -ne $true) {
    $($rest.LastErrorText)
    exit
}

#  The following code creates the JSON request body.
#  The JSON created by this code is shown below.
$jsonReq = New-Object Chilkat.JsonObject
$jsonReq.UpdateString("CertificateStatuses[0]","string")
$jsonReq.UpdateNumber("MaxItems","number")
$jsonReq.UpdateString("NextToken","string")

$sbReq = New-Object Chilkat.StringBuilder
$jsonReq.EmitSb($sbReq)

$rest.AddHeader("Content-Type","application/json")

$sbJson = New-Object Chilkat.StringBuilder
$success = $rest.FullRequestSb("POST","/",$sbReq,$sbJson)
if ($success -ne $true) {
    $($rest.LastErrorText)
    exit
}

if ($rest.ResponseStatusCode -ne 200) {
    $("Received error response code: " + $rest.ResponseStatusCode)
    $("Response body:")
    $($sbJson.GetAsString())
    exit
}

$json = New-Object Chilkat.JsonObject
$json.LoadSb($sbJson)

#  The following code parses the JSON response.
#  A sample JSON response is shown below the sample code.

$i = 0
$count_i = $json.SizeOfArray("CertificateSummaryList")
while ($i -lt $count_i) {
    $json.I = $i
    $CertificateArn = $json.StringOf("CertificateSummaryList[i].CertificateArn")
    $DomainName = $json.StringOf("CertificateSummaryList[i].DomainName")
    $i = $i + 1
}

$("Example Completed.")

Sample JSON Request Body

{
   "CertificateStatuses": [ "string" ],
   "MaxItems": number,
   "NextToken": "string"
}

Sample JSON Response Body

{"CertificateSummaryList": [
  {
    "CertificateArn": "arn:aws:acm:us-east-1:111122223333:certificate/12345678-1234-1234-1234-123456789012",
    "DomainName": "www.example.com"
  },
  {
    "CertificateArn": "arn:aws:acm:us-east-1:111122223333:certificate/87654321-5678-5678-5678-210987654321",
    "DomainName": "www.example.net"
  }
]}