Skip to content

Instantly share code, notes, and snippets.

@Rugby-Ball
Created April 16, 2024 03:32
Show Gist options
  • Select an option

  • Save Rugby-Ball/0287d1e20c7013b15f79d505af47de8b to your computer and use it in GitHub Desktop.

Select an option

Save Rugby-Ball/0287d1e20c7013b15f79d505af47de8b to your computer and use it in GitHub Desktop.
For Azure, get inventory of backups for all Subscriptions. Saved to a CSV file. #Utility #Public #Inventory #Backup #Azure
# Azure-backup-Inventory.ps1
<#
Description: For Azure, get inventory of backups for all Subscriptions. Saved to a CSV file.
Original: https://stackoverflow.com/a/63116991/9776353
Edited by: Ed Walsh
PowerShell.Core tested: Yes
MS-Graph: No
Version: 1.0.0
Create Date: 4/15/2024
Revised Date: 4/15/2024
#>
# You don't need the next two lines for every run of script, once a day should be enough.
# Connect-AzAccount
# Login-AzAccount -Subscription "Your-Subscription-Name-Here"
Clear-Host
$timestamp = get-date -format yyyyMMddHHmmss
$subfolder = if (($PSVersionTable.PSEdition) -eq "Core") { if ( $True -eq $iswindows ) { "\Documents\" } Else { "" } } Else { "\Documents\" }
$mydocuments = $home + $subfolder
$fileName = "Azure-backup-Inventory-" + [string]$timestamp + ".csv"
$filePath = Join-Path $mydocuments $fileName
$Out = @()
$subscriptions = Get-AzSubscription
ForEach ($Subscription in $Subscriptions) {
Set-AzContext -SubscriptionId $Subscription.Id | Out-Null
$sub_id = $Subscription.id
$sub_name = $Subscription.Name
$RCvaults = get-azrecoveryservicesvault
ForEach ($RCvault in $RCvaults)
{
Set-AzRecoveryServicesVaultContext -Vault $RCvault
$out += Get-AzRecoveryServicesBackupJob | Select-Object @{Name = "Subscription_ID";e={$sub_id}}, @{Name = "Subscription_Name";e={$sub_name}}, *
}
}
$out | Export-Csv -NoTypeInformation -Path $filepath
Write-Output "Exported to: $filePath"
Write-Output "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|||||||////////////////////////////////////"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment