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 22 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 @@ -171,7 +171,8 @@ private void RunSimpleCmdlet()
tagValue: null,
filter: this.ODataQuery);

var odataQuery = new Rest.Azure.OData.ODataQuery<GenericResourceFilter>(expression);
var odataQuery = new Rest.Azure.OData.ODataQuery<Azure.Management.Resources.Models.GenericResourceFilterWithExpand>(expression);
odataQuery.Expand = "createdTime,changedTime";
var result = Enumerable.Empty<PSResource>();
if (!ShouldListBySubscription(ResourceGroupName, Name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,7 @@ public virtual PSResourceGroup UpdatePSResourceGroup(PSUpdateResourceGroupParame
public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable tag, bool detailed, string location = null)
{
List<PSResourceGroup> result = new List<PSResourceGroup>();

ODataQuery<ResourceGroupFilter> resourceGroupFilter = null;
ODataQuery<ResourceGroupFilterWithExpand> resourceGroupFilter = null;

if (tag != null && tag.Count >= 1)
{
Expand All @@ -891,9 +890,15 @@ 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);
}
else
{
resourceGroupFilter = new ODataQuery<ResourceGroupFilterWithExpand>();
}

resourceGroupFilter.Expand = "createdTime,changedTime";

if (string.IsNullOrEmpty(name) || WildcardPattern.ContainsWildcardCharacters(name))
{
Expand Down Expand Up @@ -924,7 +929,7 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
{
try
{
PSResourceGroup resourceGroup = ResourceManagementClient.ResourceGroups.Get(name).ToPSResourceGroup();
PSResourceGroup resourceGroup = ResourceManagementClient.ResourceGroups.Get(name, expand: "createdTime,changedTime").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 @@ -1155,25 +1155,25 @@ private void CancelDeploymentAtResourceGroup(List<PSDeployment> deployments, str
}
}

public virtual IEnumerable<PSResource> ListResources(Rest.Azure.OData.ODataQuery<GenericResourceFilter> filter = null, ulong first = ulong.MaxValue, ulong skip = ulong.MinValue)
public virtual IEnumerable<PSResource> ListResources(Rest.Azure.OData.ODataQuery<Azure.Management.Resources.Models.GenericResourceFilterWithExpand> filter = null, ulong first = ulong.MaxValue, ulong skip = ulong.MinValue)
{
return new GenericPageEnumerable<GenericResourceExpanded>(
delegate ()
{
return ResourceManagementClient.Resources.List(filter);
return ResourceManagementClient.Resources.List(filter?.Filter);
}, ResourceManagementClient.Resources.ListNext, first, skip).Select(r => new PSResource(r));
}

public virtual IEnumerable<PSResource> ListByResourceGroup(
string resourceGroupName,
Rest.Azure.OData.ODataQuery<GenericResourceFilter> filter,
Rest.Azure.OData.ODataQuery<Azure.Management.Resources.Models.GenericResourceFilterWithExpand> filter,
ulong first = ulong.MaxValue,
ulong skip = ulong.MinValue)
{
return new GenericPageEnumerable<GenericResourceExpanded>(
delegate ()
{
return ResourceManagementClient.Resources.ListByResourceGroup(resourceGroupName, filter);
return ResourceManagementClient.Resources.ListByResourceGroup(resourceGroupName, filter?.Filter);
}, ResourceManagementClient.Resources.ListByResourceGroupNext, first, skip).Select(r => new PSResource(r));
}

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 @@ -37,7 +37,7 @@ public partial interface IResourcesOperations
/// <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<GenericResourceExpanded>>> ListByResourceGroupWithHttpMessagesAsync(string resourceGroupName, Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilter> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilter>), 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<GenericResourceExpanded>>> ListByResourceGroupWithHttpMessagesAsync(string resourceGroupName, Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilterWithExpand> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilterWithExpand>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

/// <summary>
/// The resources to be moved must be in the same source resource group in the
Expand Down Expand Up @@ -128,7 +128,7 @@ public partial interface IResourcesOperations
/// <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<GenericResourceExpanded>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilter> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilter>), 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<GenericResourceExpanded>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilterWithExpand> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<GenericResourceFilterWithExpand>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

/// <summary>
/// Checks whether a resource exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public GenericResource()

/// <param name="identity">The identity of the resource.
/// </param>
public GenericResource(string id = default(string), string name = default(string), string type = default(string), string location = default(string), ExtendedLocation extendedLocation = default(ExtendedLocation), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>), Plan plan = default(Plan), object properties = default(object), string kind = default(string), string managedBy = default(string), Sku sku = default(Sku), Identity identity = default(Identity))

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

/// <param name="changedTime">The changed time of the resource. This is only present if requested via the
/// $expand query parameter.
/// </param>
public GenericResource(string id = default(string), string name = default(string), string type = default(string), string location = default(string), ExtendedLocation extendedLocation = default(ExtendedLocation), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>), Plan plan = default(Plan), object properties = default(object), string kind = default(string), string managedBy = default(string), Sku sku = default(Sku), Identity identity = default(Identity), System.DateTime? createdTime = default(System.DateTime?), System.DateTime? changedTime = default(System.DateTime?))

: base(id, name, type, location, extendedLocation, tags)
{
Expand All @@ -69,6 +77,8 @@ public GenericResource()
this.ManagedBy = managedBy;
this.Sku = sku;
this.Identity = identity;
this.CreatedTime = createdTime;
this.ChangedTime = changedTime;
CustomInit();
}

Expand Down Expand Up @@ -113,6 +123,20 @@ public GenericResource()
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "identity")]
public Identity Identity {get; set; }

/// <summary>
/// Gets the created time of the resource. 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. 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
Expand Up @@ -73,10 +73,8 @@ public GenericResourceExpanded()
/// </param>
public GenericResourceExpanded(string id = default(string), string name = default(string), string type = default(string), string location = default(string), ExtendedLocation extendedLocation = default(ExtendedLocation), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>), Plan plan = default(Plan), object properties = default(object), string kind = default(string), string managedBy = default(string), Sku sku = default(Sku), Identity identity = default(Identity), System.DateTime? createdTime = default(System.DateTime?), System.DateTime? changedTime = default(System.DateTime?), string provisioningState = default(string))

: base(id, name, type, location, extendedLocation, tags, plan, properties, kind, managedBy, sku, identity)
: base(id, name, type, location, extendedLocation, tags, plan, properties, kind, managedBy, sku, identity, createdTime, changedTime)
{
this.CreatedTime = createdTime;
this.ChangedTime = changedTime;
this.ProvisioningState = provisioningState;
CustomInit();
}
Expand All @@ -87,20 +85,6 @@ public GenericResourceExpanded()
partial void CustomInit();


/// <summary>
/// Gets the created time of the resource. 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. 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>
/// Gets the provisioning state of the resource. This is only present if
/// requested via the $expand query parameter.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 GenericResourceFilterWithExpand : GenericResourceFilter
{
/// <summary>
/// Initializes a new instance of the GenericResourceFilterWithExpand class.
/// </summary>
public GenericResourceFilterWithExpand()
{
CustomInit();
}

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

/// <param name="resourceType">The resource type.
/// </param>

/// <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 GenericResourceFilterWithExpand(string resourceType = default(string), string tagname = default(string), string tagvalue = default(string), string expand = default(string))

: base(resourceType, 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; }
}
}
Loading
Loading