How to retrieve the most recent modified (activity)time and the ResourceName(Id) of an AzResource that has been active for the last 90 days PowerShell

212 views Asked by At

In order to cutoff the cost. I need to deprecate or move those resources that have not been in use for the last 90 days. How to automate this task in PowerShell?

With the help of Get-AzureRmLog I got all the resource logs and the timestamps.

Now I need to filter the most recent change date and their status.

If the status is Active, I need to shortlist (remove) separately, else the same. I need to automate this task every 15 days.

If anyone knows the script, please help. Priority

1

There are 1 answers

0
KrishnaG On

Get-AzActivityLog cmdlet has EventTimeStamp parameter so using where-object cmdlet pull all logs that are since 90 days and then get list of resources using ResourceId parameter. Use Get-AzResource and then get list of resources. Now, compare the difference of resources.