最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powershell - How to Retrieve Amount of Storage Backed up (in GB) by Azure? - Stack Overflow

programmeradmin8浏览0评论

I am tasked with retrieving information about a given Azure Backup Vault, and whether the backup(s) are successful or unsuccessful. If successful, I must record how much data has been backed up through a PowerShell function.

I was able to find a command that gave me the backup date(s) and the progress of each backup; however, I was not able to find a command or a set of commands that told me how much data has been backed up for each.

This is the function I have so far, it only gives me the list of backup jobs:

Function Get-AzBackupInfo
{
  $nameList = (Get-AzRecoveryServicesVault).Name
  $resourceGroupList = (Get-AzRecoveryServicesVault).ResourceGroupName
  $hostname = hostname

  for ($i = 0; $i -lt $nameList.Length; $i++)
  {
    if ($resourceGroupList[$i] -match $hostname)
    {
     $var = Get-AzRecoveryServicesVault -Name $nameList[$i] -ResourceGroupName $resourceGroupList[$i]
     $jobList = Get-AzRecoveryServicesBackupJob -VaultId $var.ID

    }
  }
   $jobList
}

Are there any modifications / additions I can make to this function that will give me the amounts of data (in GB) that have been backed up?

I am tasked with retrieving information about a given Azure Backup Vault, and whether the backup(s) are successful or unsuccessful. If successful, I must record how much data has been backed up through a PowerShell function.

I was able to find a command that gave me the backup date(s) and the progress of each backup; however, I was not able to find a command or a set of commands that told me how much data has been backed up for each.

This is the function I have so far, it only gives me the list of backup jobs:

Function Get-AzBackupInfo
{
  $nameList = (Get-AzRecoveryServicesVault).Name
  $resourceGroupList = (Get-AzRecoveryServicesVault).ResourceGroupName
  $hostname = hostname

  for ($i = 0; $i -lt $nameList.Length; $i++)
  {
    if ($resourceGroupList[$i] -match $hostname)
    {
     $var = Get-AzRecoveryServicesVault -Name $nameList[$i] -ResourceGroupName $resourceGroupList[$i]
     $jobList = Get-AzRecoveryServicesBackupJob -VaultId $var.ID

    }
  }
   $jobList
}

Are there any modifications / additions I can make to this function that will give me the amounts of data (in GB) that have been backed up?

Share Improve this question edited Mar 21 at 18:16 mimi m asked Mar 21 at 18:12 mimi mmimi m 311 silver badge5 bronze badges 1
  • 1 Add Get-AzRecoveryServicesBackupJobDetails to fetch BackupSizeInBytes and convert it to GB. @mimim – Vinay B Commented Mar 25 at 3:09
Add a comment  | 

1 Answer 1

Reset to default 1

How to Retrieve Amount of Storage Backed up (in GB) by Azure?

You can use the below PowerShell script which fetches the usage of Azure recovery vault.

Script:

$subscriptionId = "xxxx"
$resourceGroupName = "xx"
$vaultName = "vxxxd"
$apiVersion = "2024-10-01"


$uri = "https://management.azure/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.RecoveryServices/vaults/$vaultName/usages?api-version=$apiVersion"

$accessToken = (Get-AzAccessToken -ResourceUrl "https://management.azure").Token

# Call the API
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers @{ Authorization = "Bearer $accessToken" }

# Convert Byte values to GB
$convertedResponse = $response.value | ForEach-Object {
    if ($_.unit -eq "Bytes") {
        $_.currentValue = "{0:N2} GB" -f ($_.currentValue / 1GB)
    }
    $_
}

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

The above script retrieves the usage details of an Azure Recovery Services vault by calling the Azure REST API. It authenticates using Get-AzAccessToken, fetches the usage details via Invoke-RestMethod, and converts byte values to GB for readability before displaying them in a table.

Output:

Reference:

  • Usages - List By Vaults - REST API (Azure Recovery Services) | Microsoft Learn
  • How to obtain the total amount of Backup storage in GB or TB with a script - Microsoft Q&A by TP.
发布评论

评论列表(0)

  1. 暂无评论