Reputation: 991
Following SO answer provided me with a solution that I've been using for some time. But now for some reason if I execute the following code The errorvariable has no effect :(
I've tested the following code without resource group name which gives me output of all the recovery service vaults in my subscription and with the resourcegroupname paramerer which gives me no output at all.
How come this code that seems to be obvious does not work for this situation ? Can anyone see what I am missing, don't see here?
Get-AzRecoveryServicesVault -ResourceGroupName xxxxxxxxxx -ErrorVariable notPresent -ErrorAction SilentlyContinue
if($notpresent){
Write-Host -ForegroundColor "There is no backup vault available"
}
else
{
write-host -ForegroundColor Yellow "there is more than one backup vault available"
}
Upvotes: 0
Views: 466
Reputation: 42143
This command Get-AzRecoveryServicesVault -ResourceGroupName xxxxxxxxxx
will return nothing instead of error message when there is no result, so your script will not work.
So your script could be like below.
$vault = Get-AzRecoveryServicesVault -ResourceGroupName <ResourceGroupName>
if($vault){
Write-Host "there is more than one backup vault available"
}
else
{
Write-Host "There is no backup vault available"
}
Upvotes: 1