Forum Discussion
Script only giving output of failure status
I have prepared backup status report for azure vms. it is running but giving only faliour output. I need status, weather it is inprogress or completed or failure.
can any one please help.
$ErrorActionPreference = "SilentlyContinue"
$report_object =$null
$report_object = @()
# Login to Azure Account
try
{
Login-AzAccount -ErrorAction Stop
}
catch
{
# The exception lands in [Microsoft.Azure.Commands.Common.Authentication.AadAuthenticationCanceledException]
Write-Host "User Cancelled The Authentication" -ForegroundColor Yellow
exit
}
Select-AzureRmSubscription -SubscriptionId Pay-As-You-Go
$server_list =get-AzureRmvm |select Name
$azure_recovery_services_vault_list = Get-AzureRmRecoveryServicesVault
foreach($azure_recovery_services_vault_list_iterator in $azure_recovery_services_vault_list){
#Setting context
Set-AzRecoveryServicesVaultContext -Vault $azure_recovery_services_vault_list_iterator
log "Creating the hash table..."
$container_list = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVM
foreach($container_list_iterator in $container_list){
$backup_item = Get-AzureRmRecoveryServicesBackupItem -Container $container_list_iterator -WorkloadType AzureVM
$backup_item_last_backup_status = $backup_item.LastBackupStatus
#$backup_item_latest_recovery_point = $backup_item.LatestRecoveryPoint
foreach($server_list_iterator in $server_list) {
if($server_list_iterator -match $container_list_iterator.FriendlyName) {
if($backup_item_last_backup_status -eq "Completed"){
$backup_status = "Completed"
}
if($backup_item_last_backup_status -eq "InProgress"){
$backup_status = "InProgress"}
else{$backup_status = "Failed"}
$report_object_temp = new-object psobject
$report_object_temp | Add-Member -MemberType NoteProperty -Name "Servername" -Value $container_list_iterator.FriendlyName
$report_object_temp | add-member -MemberType NoteProperty -Name "Backup status" -Value $backup_status
$report_object_temp | Add-Member -MemberType NoteProperty -Name "Subscription" -Value $sub.Name
$report_object += $report_object_temp
}
}
}
}
$report_object |export-csv "c:\temp\backup_report_test.csv"
1 Reply
- farismalaebSteel Contributor
So the $report_object is only having the $backup_status = "Failed" then this mean the backup is failed
Explain something more please, are you getting the Failed as the VM backup failed, or you are getting an exception failure
Easy thing to do is to use PowerShell_ISE and try to debug F11 line by line to see whats going on.