Azure Application Gateway Certificate Name

Welcome Forums General PowerShell Q&A Azure Application Gateway Certificate Name

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 weeks, 1 day ago.

  • Author
    Posts
  • #173344

    Participant
    Topics: 3
    Replies: 3
    Points: 12
    Rank: Member

    Hi All,

    I am using a script to check all certificate on Azure App Gateway that are going to expire in next 30 days. And somehow I managed to find information but the most important part Name of cert is missing in output.

    Please help me to get this populated, since without it is too tough to find cert.

    function Test-CertExpiresSoon($cert) {
    $span = [TimeSpan]::FromDays(30)
    $today = [DateTime]::Today
    return ($cert.NotAfter – $today) -lt $span
    }

    function Decode-Certificate($certBytes) {
    $p7b = New-Object System.Security.Cryptography.Pkcs.SignedCms
    $p7b.Decode($certBytes)
    return $p7b.Certificates[0]
    }

    $gateways = Get-AzureRmApplicationGateway -Name "appgw-test" -ResourceGroupName "appgw-rg"

    foreach ($gw in $gateways) {
    foreach ($cert in $gw.SslCertificates) {
    $certBytes = [Convert]::FromBase64String($cert.PublicCertData)
    $x509 = Decode-Certificate $certBytes

    if (Test-CertExpiresSoon $x509) {
    [PSCustomObject] @{
    ResourceGroup = $gw.ResourceGroupName;
    AppGateway = $gw.Name;
    CertSubject = $x509.Subject;
    CertThumbprint = $x509.Thumbprint;
    CertExpiration = $x509.NotAfter;
    CertName = $x509.SubjectName;
    }
    }
    }
    }

     

    The CertName is coming like this, except this everything is fine:-

     

    CertName : System.Security.Cryptography.X509Certificates.X500DistinguishedName

  • #173605

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Hello Gourav,

    Unfortunately, I don't have App Gateway up and running. We will need a bit more details. What is the output for the following command?

    $x509.SubjectName | GM

You must be logged in to reply to this topic.