3

I need to use the command Get-AzureRMResource and return resources created after a particular date . Is it possible to filter the resources w.r.t creation date. Can someone please help?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Melbin K
  • 55
  • 1
  • 2
  • 6
  • 1
    This isn't really a PowerShell problem as I think you will be limited by the data stored by Azure. The cmdlet you mention does not retrieve the creation details - this is stored in the Azure log, which typically only holds 30 days of data. – boxdog Nov 19 '18 at 15:49
  • 1
    Can I get the resource Id from get Azure rm resource and pass it to Azure log. But still it can return only the items created on past 90 days..is there any other way to get the creation time of a Azure resource. – Melbin K Nov 19 '18 at 15:52
  • I don't think there is, but would be happy to be proved wrong! In any case, I think the question is best asked somewhere like [DevOps](https://devops.stackexchange.com/), [ServerFault](https://serverfault.com/) or [SuperUser](https://superuser.com/). – boxdog Nov 19 '18 at 15:59

3 Answers3

2

The Get-AzureRMResource could not get the creation date of Azure RM Resources. It seems there is no other way to get the creation date except the Activity log.

But still it can return only the items created on past 90 days.

For this issue, you could try to Archive the Azure Activity Log, this option is useful if you would like to retain your Activity Log longer than 90 days (with full control over the retention policy) for audit, static analysis, or backup.

Update:

If you want to get resources created after a particular date, try the command below, it returns the resources created after 11/20/2018 1:57:19 AM.

Get-AzureRmResourceGroupDeployment -ResourceGroupName "<ResourceGroupName>" | Where-Object {$_.Timestamp -gt '11/20/2018 1:57:19 AM'}

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • is it a good idea to use the Get-AzureRmResourceGroupDeployment command which has the time stamp . But how to find the Associated deployment id corresponding to each resource? – Melbin K Nov 20 '18 at 13:33
  • @MelbinK Not sure, actually you want to get resources created after a particular date? If so, see my update. – Joy Wang Nov 21 '18 at 01:33
1

This information is available via ARM, but you have to call the API directly rather than the PS Get-AzureRMResource (or Get-AzResource) cmdlets.

See Deleting all resources in an Azure Resource Group with age more than x days.

Essentially, you need to add the $expand=createdTime to your query parameters, ie.:

GET https://management.azure.com/subscriptions/1237f4d2-3dce-4b96-ad95-677f764e7123/resourcegroups?api-version=2019-08-01&%24expand=createdTime

kwill
  • 10,867
  • 1
  • 28
  • 26
0

Like @kwill suggested, this site can also help run the command interactively via your browser and return these results for you:

https://learn.microsoft.com/en-us/rest/api/resources/resources/list#code-try-0

Steps below:

  1. Click on the try it now button
  2. Enter your subscription ID
  3. For a key value name use: $expand For the key value value use: createdTime
  4. Then run the query and it should produce a JSON file for you

Example

kudu-star
  • 16
  • 4