DevOps | Scripts | Automation

AzurePowershell

How to get Azure Application Gateway certificate details?

Problem with AZ native command.

To get the Azure APP gateway certificate, If we you are using AZ module, then you can use Get-AzApplicationGateway command.

$appg = Get-AzApplicationGateway -Name TestAppG

There are two types of SSL certificates (FrontEnd and BackEnd). To get the FrontEnd certificate, you can use SSLCertificates property, and to get the certificate data, we need to use PublicCertData property. For example,

$appg.SslCertificates.PublicCertData

For the backend certificate, you can use AuthenticationCertificates property and to get the certificate data you can use “Data” property.

$appg.AuthenticationCertificates.Data

The output of the certificate data will be in the PKCS7 format. You need to use some commands or tricks to read PKSC7 certificate. Even if you are using AzureRM module or Get-AzApplicationGatewaySSLCertificate, the same output will be retrieved.

Using AzureRMAppGWCert Module

This PowerShell module available at PowerShell gallery, retrieves the certificate data from Azure ApplicationService App Gateway. You can Install this module from command line using, available from PowerShell gallery.

https://www.powershellgallery.com/packages/AzureRMAppGWCert/1.0.8

To install Module,

Install-Module -Name AzureRMAppGWCert
With AzureRM Module

When you use the AzureRM module, you can directly import this module after installing and run the command. For example,

Import-Module -Name AzureRMAppGWCert

PS C:\> Get-AzureRMAppGWCert -RG OfficeClient -AppGWName AppGateway

Output:

Output from PowerShell Gallery
AzureRMAppGWCert Module for AZ

AzureRMAppGWCert module only built with AzureRM cmdlets. If you need to use this module in AZ, then you need to modify module’s .psm1 file.

To do so, open the PS gallery module link, and click on AzureRMAppGWCert.psm1 from the FileList.

Copy the entire content to the PowerShell ISE or any other editor and replace the Get-AzureRmApplicationGateway command with Get-AzApplicationGateway. You can save this file as .psm1 to the PowerShell modules folder on the local system.

Or you can download the modified ps1 file from the below github location.

https://github.com/chiragce17/AzAppGatewayCert/blob/main/GetAzAppGCertificates.ps1

To run the script,

PS C:\Temp> .\GetAzAppGCertificates.ps1 -RG 'RGName' -AppGWName 'Application Gateway'

The above script retrieves both frontend and backend certificates.

Loading