Azure App Registrations – Export certificates and secrets details

By Saad Khamis

December 13, 2022

25925 views

Introduction

This PowerShell function returns information about Azure App Registrations certificates and secrets, including expiry date, days left to expire, owner and other information.

Returned information can be filtered, for example, by days left to expire and imported to CSV.

Commands

Add-MemberAdds custom properties and methods to an instance of a PowerShell object.
Get-MgApplicationGet the properties and relationships of an application object.
Get-MgApplicationOwnerDirectory objects that are owners of the application.
New-ObjectCreates an instance of a Microsoft .NET Framework or COM object.

Function

Examples

You must first call Connect-MgGraph command to sign in with the required scopes.

1. Returns all Azure Application Registrations that have certificates, secrets or both.

2. Returns all Azure Application Registrations that have certificates, secrets or both with Daysleft less than zero, expired.

3. Returns all Azure Application Registrations that have certificates, secrets or both and save them to CSV file.

4. Returns certificates for Azure Application Registration named ‘Connect to Dynamics’.

5. Returns Secrets for Azure Application Registration named ‘Connect to Dynamics’.

Function Explanation

Functions accepts two parameters:

  1. Entity: Set it to “Certificates”, “Secrets” or “Certificates,Secrets”.
  2. Filter: (Optional) to include in Get-MgApplication.

Entity is set as parameter which can take values from the incoming pipeline object, example 5.

Entity values are converted to value that is used to acquire the required values:

  1. Certificates -> KeyCredentials.
  2. Secrets -> PasswordCredentials.

New-Object and Add-Object are used to create a custom object.

In conclusion

In summary, we explored how to get information about Azure App Registrations certificates and secrets.

Did you find this function easy to follow and helpful to you? I certainly would love to hear your feedback and suggestions. So, let me know in the comments below. Happy PowerShelling.

Disclaimer

Purpose of the code contained in blog is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

Comments

There's no comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Windows – Get all installed patches, updates and hotfixes

By Saad Khamis 36258 views October 25, 2023

Azure – Get Storage Account Lifecycle Management Policy Rules

By Saad Khamis 44657 views October 12, 2023

Azure – NSG Flow Logs Explorer

By Saad Khamis 30998 views June 23, 2023

Azure SQL Server: Get Azure SQL Server Firewall Rules

By Saad Khamis 40405 views August 25, 2022