azure - 如何使用 powershell 检查 azure 虚拟机上是否启用了备份

标签 azure azure-powershell azure-backup-vault

如何使用 PowerShell 检查 Azure 虚拟机上是否启用了备份?

我知道查询所有虚拟机,然后与恢复服务保管库下配置的虚拟机进行比较。

有什么方法可以从虚拟机对象中提取信息吗?或者比我已有的更简单的方法?

最佳答案

#change the below values
$ResourceGroupName= "spfarm" #all the VMs in this Resource Group will be checked for Vault specified below
$VaultName = "vault595" 

Get-AzureRmRecoveryServicesVault -Name $VaultName -ResourceGroupName $ResourceGroupName | Set-AzureRmRecoveryServicesVaultContext
$fnames = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" | select  -ExpandProperty friendlyname
$vaultVMs=@()
foreach ($name in $fnames)
{
    $nameContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName $name
    $vaultVMs += Get-AzureRmRecoveryServicesBackupItem -Container $nameContainer -WorkloadType "AzureVM" | select VirtualMachineId
}

 $vms = Get-AzureRmVM -ResourceGroupName $ResourceGroupName
 foreach ($vm in $vms)
 {
    $j = 0;
    for ($i=0; $i -lt $vaultVMs.Count; $i++)
    {
        if ($vm.id -eq $vaultVMs[$i].VirtualMachineId)
        {
               $j++
        }
    }
    if ($j -eq 0)
    {
        Write-Host "$($vm.name) is not backed up in this vault"
    }
    else
    {
        Write-Host "$($vm.Name) is backed up in this vault"
    }
 }

关于azure - 如何使用 powershell 检查 azure 虚拟机上是否启用了备份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50023286/

相关文章:

azure - 比较 : Azure Functions vs Azure Batch

azure - 递归列出 Azure 资源组中的所有资源标签

powershell - 获取 ARM 设置的存储帐户类型

在 Azure 门户中使用运行方式帐户创建自动化帐户后,AzureRunAsConnection 不存在

azure - Azure 备份中的保管库与快照和保管库之间有什么不同

c# - 将文件上传到 Hbase HDInsight

php - php 中 Windows Azure 的连接字符串

azure - 如何将 Web 应用程序添加到 Azure 应用程序网关的后端池?

azure - 为什么 Azure VM 还原操作会导致备份操作