All scripts
Azure AI 613
Backup-AzureResourceGroupInventory
Snapshots every resource in a resource group (name, type, location, tags) to timestamped JSON. Not a full backup, a fast before-and-after diff before you touch anything.
Backup-AzureResourceGroupInventory.ps1
<#
.SYNOPSIS
Backup-AzureResourceGroupInventory.ps1 - Snapshots a resource group's inventory to JSON.
.DESCRIPTION
Exports every resource in a resource group (name, type, location, tags) to a
timestamped JSON file. It is not a full configuration backup, it is a fast
"what did this look like before I touched it" snapshot to diff against later.
.AUTHOR
Shehryar Hassan
.EXAMPLE
.\Backup-AzureResourceGroupInventory.ps1 -ResourceGroupName "rg-prod-weu"
#>
param(
[Parameter(Mandatory=$true)]
[string]$ResourceGroupName,
[Parameter(Mandatory=$false)]
[string]$OutputPath = ".\rg-inventory-$(Get-Date -Format 'yyyyMMdd-HHmmss').json"
)
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host " Azure Resource Group Inventory Snapshot" -ForegroundColor Cyan
Write-Host "=============================================" -ForegroundColor Cyan
if (-not (Get-AzContext)) {
Write-Host "[INFO] Connecting to Azure..." -ForegroundColor Yellow
Connect-AzAccount | Out-Null
}
$rg = Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction Stop
$resources = Get-AzResource -ResourceGroupName $ResourceGroupName
$snapshot = [PSCustomObject]@{
ResourceGroup = $ResourceGroupName
Location = $rg.Location
CapturedAt = (Get-Date).ToString("o")
ResourceCount = $resources.Count
Resources = $resources | Select-Object Name, ResourceType, Location, Tags
}
$snapshot | ConvertTo-Json -Depth 6 | Out-File -FilePath $OutputPath -Encoding utf8
Write-Host "[SUCCESS] $($resources.Count) resource(s) snapshotted to: $OutputPath" -ForegroundColor Green
Write-Host "[INFO] Keep this before any bulk change, it is the fastest way to see exactly what moved." -ForegroundColor YellowRead it before you run it, and test in a safe tenant first.