Skip to content

Commit 81dd937

Browse files
author
dragonfly91
committed
Fix for 3395860: Get-AzureBackupContainer returns list of container even if it returns single container
1 parent 6b4f58e commit 81dd937

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/GetAzureBackupContainer.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public override void ExecuteCmdlet()
5454
base.ExecuteCmdlet();
5555

5656
List<AzureBackupContainer> containers = new List<AzureBackupContainer>();
57-
bool uniqueContainer = false;
5857

5958
switch (Type)
6059
{
@@ -63,18 +62,15 @@ public override void ExecuteCmdlet()
6362
containers.AddRange(GetMachineContainers());
6463
break;
6564
case AzureBackupContainerType.AzureVM:
66-
uniqueContainer = GetManagedContainers(containers);
65+
containers.AddRange(GetManagedContainers());
6766
break;
6867
default:
6968
break;
7069
}
7170

72-
if (uniqueContainer)
71+
if (containers.Count == 1)
7372
{
74-
if (containers.Any())
75-
{
76-
WriteObject(containers.First());
77-
}
73+
WriteObject(containers.First());
7874
}
7975
else
8076
{
@@ -101,8 +97,10 @@ private List<AzureBackupContainer> GetMachineContainers()
10197
}).Where(container => container.ContainerType == Type.ToString()).ToList();
10298
}
10399

104-
private bool GetManagedContainers(List<AzureBackupContainer> managedContainers)
100+
private List<AzureBackupContainer> GetManagedContainers()
105101
{
102+
List<AzureBackupContainer> managedContainers = new List<AzureBackupContainer>();
103+
106104
ContainerQueryParameters parameters = new ContainerQueryParameters();
107105
parameters.ContainerType = ManagedContainerType.IaasVM.ToString();
108106
parameters.FriendlyName = Name;
@@ -134,9 +132,7 @@ private bool GetManagedContainers(List<AzureBackupContainer> managedContainers)
134132
return new AzureBackupContainer(Vault, container);
135133
}));
136134

137-
// When container resource name and container resource group name are specified, this parameter set
138-
// identifies a container uniquely. Thus, we return just one container instead of a list.
139-
return !string.IsNullOrEmpty(Name) & !string.IsNullOrEmpty(ManagedResourceGroupName);
135+
return managedContainers;
140136
}
141137
}
142138
}

0 commit comments

Comments
 (0)