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

Viewing 1 reply thread
  • Author
    • #173344
      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
      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
      Topics: 0
      Replies: 115
      Points: 433
      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
Viewing 1 reply thread
  • The topic ‘Azure Application Gateway Certificate Name’ is closed to new replies.