Forum Discussion

Oleg_A's avatar
Oleg_A
Copper Contributor
Aug 25, 2024
Solved

List all NEW resources created within a week

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 i...
  • Kidd_Ip's avatar
    Aug 25, 2024

    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

Resources