# Azure Application Gateway Certificate Name

**URL:** <https://forums.powershell.org/t/azure-application-gateway-certificate-name/13064>\
**Category:** PowerShell Help\
**Created:** [August 28, 2019, 2:12am UTC](https://forums.powershell.org/t/azure-application-gateway-certificate-name/13064 "2019-08-28T02:12:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gouravin](https://avatars.discourse-cdn.com/v4/letter/g/97f17d/32.png) [@gouravin](https://forums.powershell.org/u/gouravin)\
**Post date:** [August 28, 2019, 2:12am UTC](https://forums.powershell.org/t/azure-application-gateway-certificate-name/13064/1 "2019-08-28T02:12:44Z")

</div>

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;**  
**}**  
**}**  
**}**  
**}**

&nbsp;

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

&nbsp;

CertName : System.Security.Cryptography.X509Certificates.X500DistinguishedName

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [August 29, 2019, 3:06pm UTC](https://forums.powershell.org/t/azure-application-gateway-certificate-name/13064/2 "2019-08-29T15:06:55Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/azure-application-gateway-certificate-name/13064/3 "2024-05-16T20:31:43Z")

</div>


