Created
April 27, 2017 12:28
-
-
Save krnese/86eee978b2878e71b6c331e8d92a17f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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