Site icon TheWindowsUpdate.com

Get creation dates of all Azure resources under an Azure subscription

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

Overview:

One of our Azure customers raised a support ticket to find out the creation dates for all their resources on their Azure subscription.

This blog shows you one of the ways to achieve that.

 

Step 1:

Create an Azure service principal with the az ad sp create-for-rbac command. Make sure to copy the output, as it is required in the next steps.

 

Input

az ad sp create-for-rbac --name serviceprincipalname --role reader

 

Output

Creating 'reader' role assignment under scope '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli

'name' property in the output is deprecated and will be removed in the future. Use 'appId' instead.

{

  "appId": "xxxxxxx",

  "displayName": "serviceprincipalname",

  "name": "xxxxxxx",

  "password": "xxxxxxx",

  "tenant": "xxxxxxx"

}

 

 

Step 2:

Generate the bearer token using Postman client - Postman API Platform

 

Type in the below URL with your tenant ID for a POST call

https://login.microsoftonline.com/xxxxtenant-IDxxxxxx/oauth2/token

 

 

Click on “Body” and type in the details from the output of Step 1 as following.

Note: Client ID = App ID.

 

Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials

client_id=xxxxxxxxxxxxxxxxxxxxxx

client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxx

resource=https://management.azure.com/

 

 

Click on “Send” and you will see a JSON response as below with a bearer/access token

 

Copy the access token which will now be used in Step 3 for a Get call.

 

 

Step 3:

Make the get call to get the creation dates of your resources on the subscription. You may also do it for a single resource by filtering as needed in the URL.

Get URL - https://management.azure.com/subscriptions/XXXX-Your-Subscription- IDXXXX/resources?api-version=2020-06-01&$expand=createdTime&$select=name,createdTime 

 

Select “Bearer Token” in the Authorization tab and paste the access token copied from Step 2.

 

Click on Send and enjoy the results you wanted!

 

Credits to @P V SUHAS for the guidance.

Exit mobile version