This article is contributed. See the original author and article here.

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


 


RoshnaNazir_0-1640261795209.png


 


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/


 


RoshnaNazir_1-1640261795214.png


 


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


RoshnaNazir_2-1640261795219.png


 


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.


RoshnaNazir_3-1640261795222.png


 


Click on Send and enjoy the results you wanted!


RoshnaNazir_4-1640261795224.png


 


Credits to @P V SUHAS for the guidance.

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.