Skip to content

Instantly share code, notes, and snippets.

@krnese
Created April 27, 2017 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krnese/86eee978b2878e71b6c331e8d92a17f3 to your computer and use it in GitHub Desktop.
Save krnese/86eee978b2878e71b6c331e8d92a17f3 to your computer and use it in GitHub Desktop.
# Finding protected and unprotected VMs
$backupVaults = Find-AzureRmResource -ResourceType Microsoft.RecoveryServices/vaults
foreach ($backupvault in $backupVaults)
{
$rsVault = Get-AzureRmRecoveryServicesVault -Name $backupVault.Name -ResourceGroupName $backupVault.ResourceGroupName
Set-AzureRmRecoveryServicesVaultContext -Vault $rsVault
$azureVMs = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVM
Get-AzureRmVM | where-object {$_.Location -eq $rsVault.Location} | ForEach-Object -Process {
if ($azureVMs.FriendlyName -contains $_.Name) {
$protected = "Protected"
} else {
$protected = "Unprotected"
}
$backupTable = @()
$backupData = New-Object psobject -Property @{
VMName = $_.Name;
ProtectionStatus = $protected;
LogType = 'Backup';
VaultName = $rsVault.Name;
Location = $rsVault.Location
ResourceGroupName = $_.ResourceGroupName;
VMId = $_.Id
}
$backupTable += $backupData
$backupTableJson = ConvertTo-Json -InputObject $backupData
write-output $backuptablejson
}
$LogType = 'AzureManagement'
Send-OMSAPIIngestionData -customerId $omsworkspaceId -sharedKey $omsworkspaceKey -body $backupTableJson -logType $LogType
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment