Skip to content

Commit e1653a2

Browse files
committed
Merge pull request Azure#1148 from vivsriaus/TagForFind
Add TagName and TagValue to Find-AzureRmResource cmdlet
2 parents 8d0528c + 863b9c2 commit e1653a2

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/FindAzureResourceCmdlet.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase
101101
[ValidateNotNullOrEmpty]
102102
public string ODataQuery { get; set; }
103103

104+
/// <summary>
105+
/// Gets or sets the tag name.
106+
/// </summary>
107+
[Parameter(ParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet, Mandatory = false, HelpMessage = "The name of the tag to query by.")]
108+
[Parameter(ParameterSetName = FindAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, Mandatory = false, HelpMessage = "The name of the tag to query by.")]
109+
[ValidateNotNullOrEmpty]
110+
public string TagName { get; set; }
111+
112+
/// <summary>
113+
/// Gets or sets the tag value.
114+
/// </summary>
115+
[Parameter(ParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet, Mandatory = false, HelpMessage = "The value of the tag to query by.")]
116+
[Parameter(ParameterSetName = FindAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, Mandatory = false, HelpMessage = "The value of the tag to query by.")]
117+
[ValidateNotNullOrEmpty]
118+
public string TagValue { get; set; }
119+
104120
/// <summary>
105121
/// Gets or sets the resource group name.
106122
/// </summary>
@@ -237,8 +253,8 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesTypeCollect
237253
var odataQuery = QueryFilterBuilder.CreateFilter(
238254
resourceType: null,
239255
resourceName: null,
240-
tagName: null,
241-
tagValue: null,
256+
tagName: this.TagName,
257+
tagValue: this.TagValue,
242258
filter: this.ODataQuery,
243259
resourceGroupNameContains: this.ResourceGroupNameContains,
244260
nameContains: this.ResourceGroupNameContains);
@@ -264,8 +280,8 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInTenant()
264280
resourceGroup: null,
265281
resourceType: this.ResourceType,
266282
resourceName: null,
267-
tagName: null,
268-
tagValue: null,
283+
tagName: this.TagName,
284+
tagValue: this.TagValue,
269285
filter: this.ODataQuery,
270286
resourceGroupNameContains: this.ResourceGroupNameContains,
271287
nameContains: this.ResourceNameContains);
@@ -293,8 +309,8 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInResourceG
293309
.CreateFilter(
294310
resourceType: this.ResourceType,
295311
resourceName: null,
296-
tagName: null,
297-
tagValue: null,
312+
tagName: this.TagName,
313+
tagValue: this.TagValue,
298314
filter: this.ODataQuery,
299315
resourceGroupNameContains: this.ResourceGroupNameContains,
300316
nameContains: this.ResourceNameContains);
@@ -324,8 +340,8 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInSubscript
324340
.CreateFilter(
325341
resourceType: this.ResourceType,
326342
resourceName: null,
327-
tagName: null,
328-
tagValue: null,
343+
tagName: this.TagName,
344+
tagValue: this.TagValue,
329345
filter: this.ODataQuery,
330346
nameContains: this.ResourceNameContains);
331347

@@ -466,7 +482,9 @@ private bool IsResourceGroupLevelQuery()
466482
{
467483
return this.SubscriptionId.HasValue &&
468484
this.ResourceGroupNameContains != null &&
469-
(this.ResourceType != null ||
485+
(this.TagName != null ||
486+
this.TagValue != null ||
487+
this.ResourceType != null ||
470488
this.ExtensionResourceType != null);
471489
}
472490
}

0 commit comments

Comments
 (0)