Skip to content

Commit 705bbe3

Browse files
efloresgilisra-fel
andauthored
Add Default API Version to Get-AzResourceProvider cmdlet Resource Types array returned properties (#26542)
* Update PSResourceProviderResourceType.cs Add DefaultApiVersion of type string to the PSResourceProviderResourceType class to allow the Get-ResourceProvider cmdlet to return it * Update GetAzureProviderCmdlet.cs Set the DefaultApiVersion of the Resource Type object in method OnProcessRecord() to allow the Get-AzResourceProvider cmdlet to return Default API Version information to the user * Update ChangeLog.md * connect the dots --------- Co-authored-by: Azure <[email protected]>
1 parent d880d03 commit 705bbe3

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

src/Resources/ResourceManager/Implementation/Providers/GetAzureProviderCmdlet.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ protected override void OnProcessRecord()
8686
ResourceTypeName = type.ResourceTypeName,
8787
Locations = type.Locations,
8888
ApiVersions = type.ApiVersions,
89-
ZoneMappings = type.ZoneMappings
89+
ZoneMappings = type.ZoneMappings,
90+
DefaultApiVersion = type.DefaultApiVersion
9091
}
9192
},
9293
ZoneMappings = type.ZoneMappings

src/Resources/ResourceManager/ResourceManager.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@
586586
<Label>ApiVersions</Label>
587587
<PropertyName>ApiVersions</PropertyName>
588588
</ListItem>
589+
<ListItem>
590+
<Label>DefaultApiVersion</Label>
591+
<PropertyName>DefaultApiVersion</PropertyName>
592+
</ListItem>
589593
</ListItems>
590594
</ListEntry>
591595
</ListEntries>

src/Resources/ResourceManager/SdkExtensions/ResourcesExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static PSResourceProvider ToPSResourceProvider(this Provider provider)
115115
ResourceTypeName = resourceType.ResourceType,
116116
Locations = resourceType.Locations != null ? resourceType.Locations.ToArray() : null,
117117
ApiVersions = resourceType.ApiVersions != null ? resourceType.ApiVersions.ToArray() : null,
118+
DefaultApiVersion = resourceType.DefaultApiVersion
118119
}).ToArray(),
119120
};
120121
}
@@ -214,7 +215,7 @@ public static string ConstructOutputTable(IDictionary<string, object> dictionary
214215
dictionary.Keys.ForEach(k => maxNameLength = Math.Max(maxNameLength, k.Length + 2));
215216

216217
StringBuilder output = new StringBuilder();
217-
218+
218219
if (dictionary.Count > 0)
219220
{
220221
string rowFormat = "{0, -" + maxNameLength + "} {1}\r\n";
@@ -266,7 +267,7 @@ public static string ConstructDeploymentVariableTable(Dictionary<string, Deploym
266267

267268
foreach (KeyValuePair<string, DeploymentVariable> pair in dictionary)
268269
{
269-
result.AppendFormat(rowFormat, pair.Key, pair.Value.Type,
270+
result.AppendFormat(rowFormat, pair.Key, pair.Value.Type,
270271
JsonConvert.SerializeObject(pair.Value.Value).Indent(maxNameLength + maxTypeLength + 4).Trim());
271272
}
272273
}

src/Resources/ResourceManager/SdkModels/ResourceProvider/PSResourceProviderResourceType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ public class PSResourceProviderResourceType
3939
/// Gets or sets the zone mappings that this resource supports.
4040
/// </summary>
4141
public Hashtable ZoneMappings { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets the default api version for this resource.
45+
/// </summary>
46+
public string DefaultApiVersion { get; set; }
4247
}
4348
}

src/Resources/Resources/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added DefaultApiVersion to the returned properties of the `Get-AzResourceProvider` cmdlet's Resource Type array
2223
* Added Diagnostics/Warnings to WhatIf/Validate results for deployments.
2324
* Fixed bug unexpected type issue: [#26752]
2425
* Added parameter `RequestedAccessTokenVersion` for `New-AzADApplication` and `Update-AzADApplication`
@@ -49,7 +50,7 @@
4950
* `New-AzPolicyExemption`
5051
* `Update-AzPolicyAssignment`
5152
* `Update-AzPolicyExemption`
52-
* Fixed bug deserializing property: `policyDefinitionReferenceId` [#25112]
53+
* Fixed bug deserializing property: `policyDefinitionReferenceId` [#25112]
5354
* Fixed overriding of Bicep parameters in Deployment cmdlets to support `SecureString` parameters.
5455
* Added Test cmdlets for Deployment Stacks.
5556

src/Resources/Resources/help/Get-AzResourceProvider.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ Locations : {West US, East US, North Europe, West Europe…}
214214

215215
This command Gets all the resource providers under "Microsoft.Compute" and "Microsoft.Network".
216216

217+
### Example 4: Get the default API version for a specific resource type
218+
219+
```powershell
220+
$crp = Get-AzResourceProvider -ProviderNamespace "Microsoft.Compute"
221+
$crp.ResourceTypes | Where-Object { $_.ResourceTypeName -eq "disks" }
222+
```
223+
224+
```output
225+
ResourceTypeName : disks
226+
Locations : {Southeast Asia, East US 2, Central US, West Europe…}
227+
ApiVersions : {2024-03-02, 2023-10-02, 2023-04-02, 2023-01-02…}
228+
DefaultApiVersion : 2022-03-02
229+
```
230+
231+
To get the default API version for a specific resource type, get the resource provider first then filter the resource type by name.
232+
217233
## PARAMETERS
218234

219235
### -ApiVersion

0 commit comments

Comments
 (0)