Skip to content

[Resources] Added ExpandProperties functionality to GetAzureResourceGroup #28161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cf092d6
Small fix to Test-AzResourceGroupDeployment
a0x1ab Jun 19, 2025
bca3600
added test case where there are no diagnostics and no errors
a0x1ab Jun 19, 2025
d913ffb
Merge branch 'Azure:main' into dev
a0x1ab Jun 20, 2025
ac02ac4
Update ChangeLog.md
a0x1ab Jun 20, 2025
3530ef2
Update src/Resources/Resources/ChangeLog.md
a0x1ab Jun 20, 2025
5d70050
Merge branch 'main' into dev
a0x1ab Jul 2, 2025
ef0c47d
added changes for resource group cmdlet new features
a0x1ab Jul 7, 2025
13d5ac8
Merge branch 'main' into dev
a0x1ab Jul 7, 2025
e26ba12
Merge branch 'Azure:main' into dev
a0x1ab Jul 8, 2025
2f9847f
Merge branch 'main' into dev
a0x1ab Jul 10, 2025
3580222
Add support for $expand on createdTime and changedTime
a0x1ab Jul 10, 2025
0ea5cc7
Update ChangeLog.md
a0x1ab Jul 10, 2025
413b9ba
Update ChangeLog.md
a0x1ab Jun 20, 2025
f74e6cf
Update src/Resources/Resources/ChangeLog.md
a0x1ab Jun 20, 2025
e687d0d
added changes for resource group cmdlet new features
a0x1ab Jul 7, 2025
e3f1b87
Add support for $expand on createdTime and changedTime
a0x1ab Jul 10, 2025
ac0a62e
Update ChangeLog.md
a0x1ab Jul 10, 2025
015146c
Merge branch 'dev' of https://github.com/a0x1ab/azure-powershell into…
a0x1ab Jul 10, 2025
42d0ffd
Update ChangeLog.md
a0x1ab Jul 10, 2025
73d3332
Remove duplicate test for resource group timestamps
a0x1ab Jul 10, 2025
d00d3dc
Fixed test and re-ran cassette recording
a0x1ab Jul 10, 2025
765aff4
Merge branch 'main' into dev
a0x1ab Jul 10, 2025
0843594
Reverted all recording
a0x1ab Jul 14, 2025
451790f
Merge branch 'main' into dev
a0x1ab Jul 14, 2025
1fab684
updated cmdlets, check-int tests, live tests
a0x1ab Jul 19, 2025
e95d149
Reset GetAzureResourceCommandTests
a0x1ab Jul 19, 2025
59675ca
small optimisation
a0x1ab Jul 19, 2025
8f29800
whitespace changes
a0x1ab Jul 19, 2025
32f3b68
Merge branch 'main' into dev
a0x1ab Jul 19, 2025
932ce7f
Update help for expanded properties in Get-AzResource* cmdlets
a0x1ab Jul 19, 2025
4fb474c
Expand resource group properties in test scenario
a0x1ab Jul 19, 2025
95d8693
Delete src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Co…
a0x1ab Jul 19, 2025
e976c51
Use It.IsAny<CancellationToken>() in test mocks
a0x1ab Jul 20, 2025
eb160cc
Fix tag filter logic and update test CancellationToken usage
a0x1ab Jul 20, 2025
870b2d4
Update NewResourceManagerSdkClient.cs
a0x1ab Jul 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,19 @@ public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersi
[ValidateNotNullOrEmpty]
public Hashtable Tag { get; set; }

/// <summary>
/// Gets or sets the expand properties parameter.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "When specified, output includes CreatedTime and ChangedTime of a resource.")]
public SwitchParameter ExpandProperties { get; set; }

protected override void OnProcessRecord()
{
String subscriptionId = null;
if (ResourceGroupIdParameterSet.Equals(ParameterSetName)){
ResourceIdentifier resourceIdentifier = ResourceIdentifier.FromResourceGroupIdentifier(this.Id);
Name = resourceIdentifier.ResourceGroupName;
subscriptionId = resourceIdentifier.Subscription;
}
this.WriteObject(ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location, subscriptionId), true);
this.WriteObject(this.NewResourceManagerSdkClient.FilterResourceGroups(this.Name, this.Tag, false, this.Location, this.ExpandProperties), true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,14 @@ public virtual PSResourceGroup UpdatePSResourceGroup(PSUpdateResourceGroupParame
/// <param name="tag">The resource group tag.</param>
/// <param name="detailed">Whether the return is detailed or not.</param>
/// <param name="location">The resource group location.</param>
/// <param name="expand">The expand parameter for optional response properties.</param>
/// <returns>The filtered resource groups</returns>
public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable tag, bool detailed, string location = null)
public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable tag, bool detailed, string location = null, bool expand = false)
{
List<PSResourceGroup> result = new List<PSResourceGroup>();
var resourceGroupFilter = new ODataQuery<ResourceGroupFilterWithExpand>();

ODataQuery<ResourceGroupFilter> resourceGroupFilter = null;

if (tag != null && tag.Count >= 1)
if (tag?.Count >= 1)
{
PSTagValuePair tagValuePair = TagsConversionHelper.Create(tag);
if (tagValuePair == null || tag.Count > 1)
Expand All @@ -891,8 +891,12 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
}

resourceGroupFilter = string.IsNullOrEmpty(tagValuePair.Value)
? new ODataQuery<ResourceGroupFilter>(rgFilter => rgFilter.TagName == tagValuePair.Name)
: new ODataQuery<ResourceGroupFilter>(rgFilter => rgFilter.TagName == tagValuePair.Name && rgFilter.TagValue == tagValuePair.Value);
? new ODataQuery<ResourceGroupFilterWithExpand>(rgFilter => rgFilter.TagName == tagValuePair.Name)
: new ODataQuery<ResourceGroupFilterWithExpand>(rgFilter => rgFilter.TagName == tagValuePair.Name && rgFilter.TagValue == tagValuePair.Value);
}

if (expand) {
resourceGroupFilter.Expand = "createdTime,changedTime";
}

if (string.IsNullOrEmpty(name) || WildcardPattern.ContainsWildcardCharacters(name))
Expand Down Expand Up @@ -924,7 +928,10 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
{
try
{
PSResourceGroup resourceGroup = ResourceManagementClient.ResourceGroups.Get(name).ToPSResourceGroup();
PSResourceGroup resourceGroup = expand
? ResourceManagementClient.ResourceGroups.Get(name, expand: "createdTime,changedTime").ToPSResourceGroup()
: ResourceManagementClient.ResourceGroups.Get(name).ToPSResourceGroup();

if (string.IsNullOrEmpty(location) || resourceGroup.Location.EqualsAsLocation(location))
{
result.Add(resourceGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup
ProvisioningState = resourceGroup.Properties == null ? null : resourceGroup.Properties.ProvisioningState,
Tags = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags),
ResourceId = resourceGroup.Id,
ManagedBy = resourceGroup.ManagedBy
ManagedBy = resourceGroup.ManagedBy,
CreatedTime = resourceGroup.CreatedTime,
ChangedTime = resourceGroup.ChangedTime
};

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
using System;
using System.Collections;
using System.Collections.Generic;

Expand All @@ -36,5 +37,9 @@ public string TagsTable
public string ResourceId { get; set; }

public string ManagedBy { get; set; }

public DateTime? CreatedTime { get; set; }

public DateTime? ChangedTime { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public partial interface IResourceGroupsOperations
/// <param name='resourceGroupName'>
/// The name of the resource group to get. The name is case insensitive.
/// </param>
/// <param name='expand'>
/// Comma-separated list of additional properties to be included in the
/// response. Valid values include createdTime, changedTime.
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
Expand All @@ -111,7 +115,7 @@ public partial interface IResourceGroupsOperations
/// <exception cref="Microsoft.Rest.SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, string expand = default(string), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

/// <summary>
/// Resource groups can be updated through a simple PATCH operation to a group
Expand Down Expand Up @@ -190,7 +194,7 @@ public partial interface IResourceGroupsOperations
/// <exception cref="Microsoft.Rest.SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

/// <summary>
/// When you delete a resource group, all of its resources are also deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public ResourceGroup()

/// <param name="tags">The tags attached to the resource group.
/// </param>
public ResourceGroup(string location, string id = default(string), string name = default(string), string type = default(string), ResourceGroupProperties properties = default(ResourceGroupProperties), string managedBy = default(string), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>))

/// <param name="createdTime">The created time of the resource group. This is only present if requested
/// via the $expand query parameter.
/// </param>

/// <param name="changedTime">The changed time of the resource group. This is only present if requested
/// via the $expand query parameter.
/// </param>
public ResourceGroup(string location, string id = default(string), string name = default(string), string type = default(string), ResourceGroupProperties properties = default(ResourceGroupProperties), string managedBy = default(string), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>), System.DateTime? createdTime = default(System.DateTime?), System.DateTime? changedTime = default(System.DateTime?))

{
this.Id = id;
Expand All @@ -55,6 +63,8 @@ public ResourceGroup()
this.Location = location;
this.ManagedBy = managedBy;
this.Tags = tags;
this.CreatedTime = createdTime;
this.ChangedTime = changedTime;
CustomInit();
}

Expand Down Expand Up @@ -107,6 +117,20 @@ public ResourceGroup()
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "tags")]
public System.Collections.Generic.IDictionary<string, string> Tags {get; set; }

/// <summary>
/// Gets the created time of the resource group. This is only present if
/// requested via the $expand query parameter.
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "createdTime")]
public System.DateTime? CreatedTime {get; private set; }

/// <summary>
/// Gets the changed time of the resource group. This is only present if
/// requested via the $expand query parameter.
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "changedTime")]
public System.DateTime? ChangedTime {get; private set; }
/// <summary>
/// Validate the object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

namespace Microsoft.Azure.Management.Resources.Models
{
using System.Linq;

public partial class ResourceGroupFilterWithExpand : ResourceGroupFilter
{
/// <summary>
/// Initializes a new instance of the ResourceGroupFilterWithExpand class.
/// </summary>
public ResourceGroupFilterWithExpand()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the ResourceGroupFilterWithExpand class.
/// </summary>

/// <param name="tagName">The tag name.
/// </param>

/// <param name="tagValue">The tag value.
/// </param>

/// <param name="expand">Comma-separated list of additional properties to be included in the
/// response. Valid values include createdTime, changedTime.
/// </param>
public ResourceGroupFilterWithExpand(string tagName = default(string), string tagValue = default(string), string expand = default(string))

: base(tagName, tagValue)
{
this.Expand = expand;
CustomInit();
}

/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();


/// <summary>
/// Gets or sets comma-separated list of additional properties to be included
/// in the response. Valid values include createdTime, changedTime.
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "$expand")]
public string Expand {get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
/// <param name='resourceGroupName'>
/// The name of the resource group to get. The name is case insensitive.
/// </param>
/// <param name='expand'>
/// Comma-separated list of additional properties to be included in the
/// response. Valid values include createdTime, changedTime.
/// </param>
/// <param name='customHeaders'>
/// Headers that will be added to request.
/// </param>
Expand All @@ -542,7 +546,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, string expand = default(string), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{


Expand Down Expand Up @@ -577,6 +581,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
}


// Tracing
bool _shouldTrace = Microsoft.Rest.ServiceClientTracing.IsEnabled;
string _invocationId = null;
Expand All @@ -585,6 +590,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
_invocationId = Microsoft.Rest.ServiceClientTracing.NextInvocationId.ToString();
System.Collections.Generic.Dictionary<string, object> tracingParameters = new System.Collections.Generic.Dictionary<string, object>();
tracingParameters.Add("resourceGroupName", resourceGroupName);
tracingParameters.Add("expand", expand);


tracingParameters.Add("cancellationToken", cancellationToken);
Expand All @@ -602,6 +608,10 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
{
_queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(this.Client.ApiVersion)));
}
if (expand != null)
{
_queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand)));
}
if (_queryParameters.Count > 0)
{
_url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
Expand Down Expand Up @@ -1014,7 +1024,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{


Expand Down Expand Up @@ -1053,10 +1063,10 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
System.Collections.Generic.List<string> _queryParameters = new System.Collections.Generic.List<string>();
if (odataQuery != null)
{
var _resourceGroupFilter = odataQuery.ToString();
if (!string.IsNullOrEmpty(_resourceGroupFilter))
var _resourceGroupFilterWithExpand = odataQuery.ToString();
if (!string.IsNullOrEmpty(_resourceGroupFilterWithExpand))
{
_queryParameters.Add(_resourceGroupFilter);
_queryParameters.Add(_resourceGroupFilterWithExpand);
}
}
if (this.Client.ApiVersion != null)
Expand Down
Loading