SOLVED

List all NEW resources created within a week

Copper Contributor

Hello:

 

I wonder if there is a way to find out ALL Resources in our tenant that were created since specific date (like last 7 days). 

Ideally I'd like to run it via PowerShell... 

How can I do it?

 

We are not enforcing "create date" tags... I thought about Powershell, but sometimes there are CreateDate, sometimes CreateAt...

 

Thank you!

3 Replies
best response confirmed by Oleg_A (Copper Contributor)
Solution

@Oleg_A 

 

Try this:

 

Connect-AzAccount

 

$startDate = (Get-Date).AddDays(-7) # Change this to your desired start date
$endDate = Get-Date

 

$activityLogs = Get-AzActivityLog -StartTime $startDate -EndTime $endDate -MaxRecord 1000 | Where-Object { $_.OperationName -like "Microsoft.Resources/subscriptions/resourceGroups/deployments/write" }

 

$createdResources = @()
foreach ($log in $activityLogs) {
$resource = @{
ResourceId = $log.ResourceId
ResourceName = $log.ResourceId.Split('/')[-1]
ResourceType = $log.ResourceType
ResourceGroupName = $log.ResourceGroupName
SubscriptionId = $log.SubscriptionId
CreatedTime = $log.EventTimestamp
}
$createdResources += New-Object PSObject -Property $resource
}

# Display the results
$createdResources | Format-Table -AutoSize

@Kidd_Ip ,

 

Thank you very much! 

Such a great idea to use logs... 

 

I'll try tomorrow and let you know. 

 

Thank you!

@Kidd_Ip ,

Thanks a lot!!! It worked perfectly!

I just had to adjust one line:

$activityLogs = Get-AzActivityLog -StartTime $startDate -EndTime $endDate -MaxRecord 1000 | Where-Object { $_.OperationName -like "Create*"}

Thanks again!
1 best response

Accepted Solutions
best response confirmed by Oleg_A (Copper Contributor)
Solution

@Oleg_A 

 

Try this:

 

Connect-AzAccount

 

$startDate = (Get-Date).AddDays(-7) # Change this to your desired start date
$endDate = Get-Date

 

$activityLogs = Get-AzActivityLog -StartTime $startDate -EndTime $endDate -MaxRecord 1000 | Where-Object { $_.OperationName -like "Microsoft.Resources/subscriptions/resourceGroups/deployments/write" }

 

$createdResources = @()
foreach ($log in $activityLogs) {
$resource = @{
ResourceId = $log.ResourceId
ResourceName = $log.ResourceId.Split('/')[-1]
ResourceType = $log.ResourceType
ResourceGroupName = $log.ResourceGroupName
SubscriptionId = $log.SubscriptionId
CreatedTime = $log.EventTimestamp
}
$createdResources += New-Object PSObject -Property $resource
}

# Display the results
$createdResources | Format-Table -AutoSize

View solution in original post