Skip to content

Commit c37ea51

Browse files
Deprecate a parameter set for Get-AzVMSize (#27687)
1 parent 66c75cd commit c37ea51

File tree

9 files changed

+69
-85
lines changed

9 files changed

+69
-85
lines changed

src/Compute/Compute.Test/ScenarioTests/ComputeTestCommon.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,11 @@ Gets default VM size string
466466
function Get-DefaultVMSize
467467
{
468468
param([string] $location = "westus")
469-
470-
$vmSizes = Get-AzVMSize -Location $location | where { $_.NumberOfCores -ge 4 -and $_.MaxDataDiskCount -ge 8 };
469+
$vmSizes = Get-AzComputeResourceSku -Location $location | Where-Object {
470+
$_.ResourceType -eq "virtualMachines" -and
471+
([int]($_.Capabilities | Where-Object { $_.Name -eq "vCPUs" }).Value) -ge 4 -and
472+
([int]($_.Capabilities | Where-Object { $_.Name -eq "MaxDataDiskCount" }).Value) -ge 8
473+
}
471474

472475
foreach ($sz in $vmSizes)
473476
{

src/Compute/Compute.Test/ScenarioTests/VMDynamicTests.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ function get_all_standard_vm_sizes
4242

4343
$st = Write-Verbose "Getting all VM sizes in location '${location}' - Start";
4444

45-
$vmsizes = Get-AzVMSize -Location $location | where { $_.Name -like 'Standard_A*' -and $_.NumberOfCores -le 4 } | select -ExpandProperty Name;
45+
$vmsizes = Get-AzComputeResourceSku -Location $location | Where-Object {
46+
$_.Name -like 'Standard_A*' -and
47+
([int]($_.Capabilities | Where-Object { $_.Name -eq "vCPUs" }).Value) -le 4
48+
} | Select-Object -ExpandProperty Name
49+
4650

4751
$st = Write-Verbose "Getting all VM sizes in location [${location}] - End";
4852

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,6 @@ public void TestVMImageEdgeZoneCmdletOutputFormat()
164164
TestRunner.RunTestScript("Test-VMImageEdgeZoneCmdletOutputFormat");
165165
}
166166

167-
[Fact]
168-
[Trait(Category.AcceptanceType, Category.CheckIn)]
169-
public void TestGetVMSizeFromAllLocations()
170-
{
171-
TestRunner.RunTestScript("Test-GetVMSizeFromAllLocations");
172-
}
173-
174167
[Fact]
175168
[Trait(Category.AcceptanceType, Category.CheckIn)]
176169
public void TestVirtualMachineListWithPaging()

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -915,12 +915,13 @@ function Test-VirtualMachineSizeAndUsage
915915
Assert-AreEqual $vm.StorageProfile.DataDisks[1].Lun 2;
916916
Assert-AreEqual $vm.StorageProfile.DataDisks[1].Vhd.Uri $dataDiskVhdUri2;
917917

918-
# Test Sizes
919-
$s1 = Get-AzVMSize -Location ($loc -replace ' ');
920-
Assert-NotNull $s1;
921-
Assert-NotNull $s1.RequestId;
922-
Assert-NotNull $s1.StatusCode;
923-
Validate-VirtualMachineSize $vmsize $s1;
918+
# Test Sizes
919+
# CASE 1: List Virtual Machine Sizes parameter set deprecated
920+
# s1 = Get-AzVMSize -Location ($loc -replace ' ');
921+
# Assert-NotNull $s1;
922+
# Assert-NotNull $s1.RequestId;
923+
# Assert-NotNull $s1.StatusCode;
924+
# Validate-VirtualMachineSize $vmsize $s1;
924925

925926
$s2 = Get-AzVMSize -ResourceGroupName $rgname -VMName $vmname;
926927
Assert-NotNull $s2;
@@ -2168,20 +2169,6 @@ function Test-VMImageEdgeZoneCmdletOutputFormat
21682169
Assert-OutputContains " Get-AzVMImage -Location '$locStr' -EdgeZone '$edgeZone' -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');
21692170
}
21702171

2171-
# Test Get VM Size from All Locations
2172-
function Test-GetVMSizeFromAllLocations
2173-
{
2174-
$locations = get_all_vm_locations;
2175-
foreach ($loc in $locations)
2176-
{
2177-
$vmsizes = Get-AzVMSize -Location $loc;
2178-
Assert-True { $vmsizes.Count -gt 0 }
2179-
Assert-True { ($vmsizes | where { $_.Name -eq 'Standard_A3' }).Count -eq 1 }
2180-
2181-
Write-Output ('Found VM Size Standard_A3 in Location: ' + $loc);
2182-
}
2183-
}
2184-
21852172
function get_all_vm_locations
21862173
{
21872174
if ((Get-ComputeTestMode) -ne 'Playback')

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Deprecated `Get-AzVMSize` 'List Virtual Machine Size' parameter set.
2324
* Added new parameters `EnableAutomaticZoneRebalance`, `AutomaticZoneRebalanceStrategy` and `AutomaticZoneRebalanceBehavior` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS Automatic Zone Rebalancing.
2425

2526
## Version 9.3.0

src/Compute/Compute/VirtualMachineSizes/GetAzureVMSizeCommand.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,13 @@
2424

2525
namespace Microsoft.Azure.Commands.Compute
2626
{
27-
[GenericBreakingChangeWithVersion("The \"ListVirtualMachineSize\" parameter set will be deprecated as its API: \"Virtual Machine Sizes - List\" is deprecated. For listing available VM sizes by subscription or location, please use instead \"Get-AzComputeResourceSku\". Other parameter sets: \"List Available Sizes for Availability Set\" and \"List Available Sizes for Virtual Machine\" will continue to be supported.", "14.0.0", "10.0.0")]
28-
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMSize", DefaultParameterSetName = ListVirtualMachineSizeParamSet)]
27+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMSize", DefaultParameterSetName = ListAvailableSizesForVirtualMachine)]
2928
[OutputType(typeof(PSVirtualMachineSize))]
3029
public class GetAzureVMSizeCommand : VirtualMachineSizeBaseCmdlet
3130
{
32-
protected const string ListVirtualMachineSizeParamSet = "ListVirtualMachineSizeParamSet";
3331
protected const string ListAvailableSizesForAvailabilitySet = "ListAvailableSizesForAvailabilitySet";
3432
protected const string ListAvailableSizesForVirtualMachine = "ListAvailableSizesForVirtualMachine";
3533

36-
[Parameter(
37-
Mandatory = true,
38-
Position = 0,
39-
ParameterSetName = ListVirtualMachineSizeParamSet,
40-
ValueFromPipelineByPropertyName = true,
41-
HelpMessage = "The location name.")]
42-
[LocationCompleter("Microsoft.Compute/locations/vmSizes")]
43-
[ValidateNotNullOrEmpty]
44-
public string Location { get; set; }
45-
4634
[Parameter(
4735
Mandatory = true,
4836
Position = 0,
@@ -93,16 +81,12 @@ public override void ExecuteCmdlet()
9381
this.ResourceGroupName,
9482
this.VMName).GetAwaiter().GetResult();
9583
}
96-
else if (!string.IsNullOrEmpty(this.AvailabilitySetName))
84+
else
9785
{
9886
result = this.AvailabilitySetClient.ListAvailableSizesWithHttpMessagesAsync(
9987
this.ResourceGroupName,
10088
this.AvailabilitySetName).GetAwaiter().GetResult();
10189
}
102-
else
103-
{
104-
result = this.VirtualMachineSizeClient.ListWithHttpMessagesAsync(this.Location.Canonicalize()).GetAwaiter().GetResult();
105-
}
10690

10791
List<PSVirtualMachineSize> psResultList = new List<PSVirtualMachineSize>();
10892
foreach (var item in result.Body)

src/Compute/Compute/help/Get-AzComputeResourceSku.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,45 @@ Get-AzComputeResourceSku "westus";
2929

3030
List all compute resource skus in West US region
3131

32+
### Example 2
33+
```powershell
34+
Get-AzComputeResourceSku -Location "westus" | Where-Object {
35+
$_.Name -like 'Standard_A*' -and
36+
([int]($_.Capabilities | Where-Object { $_.Name -eq 'vCPUs' }).Value) -le 4
37+
} | Select-Object -ExpandProperty Name
38+
```
39+
```output
40+
Standard_A0
41+
Standard_A1
42+
Standard_A1_v2
43+
Standard_A2
44+
Standard_A2m_v2
45+
Standard_A2_v2
46+
Standard_A3
47+
Standard_A4m_v2
48+
Standard_A4_v2
49+
Standard_A5
50+
Standard_A6
51+
```
52+
53+
Get all compute resource skus in West US region, filter by name and vCPUs capability, and select the name property.
54+
55+
### Example 3
56+
```powershell
57+
$vmSizes = Get-AzComputeResourceSku -Location "WestUS" | Where-Object {
58+
$_.ResourceType -eq "virtualMachines" -and
59+
([int]($_.Capabilities | Where-Object { $_.Name -eq "vCPUs" }).Value) -ge 4 -and
60+
([int]($_.Capabilities | Where-Object { $_.Name -eq "MaxDataDiskCount" }).Value) -ge 8
61+
}
62+
$vmSizes.count
63+
```
64+
65+
```output
66+
812
67+
```
68+
69+
Get all compute resource skus in West US region, filter by resource type, vCPUs capability, and MaxDataDiskCount capability, and count the number of results.
70+
3271
## PARAMETERS
3372

3473
### -DefaultProfile

src/Compute/Compute/help/Get-AzVMSize.md

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ schema: 2.0.0
1111
## SYNOPSIS
1212
Gets available virtual machine sizes.
1313

14-
**Note**: The **List Virtual Machine Size** parameter set will be deprecated in the next major release (14.0.0) as its API: [Virtual Machine Sizes - List](https://learn.microsoft.com/en-us/rest/api/compute/virtual-machine-sizes/list) is deprecated. For listing available VM sizes by subscription or location, please use instead [Get-AzComputeResourceSku](https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azcomputeresourcesku). Other parameter sets: "List Available Sizes for Availability Set" and "List Available Sizes for Virtual Machine" will continue to be supported.
15-
1614
## SYNTAX
1715

18-
### ListVirtualMachineSizeParamSet (Default)
16+
### ListAvailableSizesForVirtualMachine (Default)
1917
```
20-
Get-AzVMSize [-Location] <String> [-DefaultProfile <IAzureContextContainer>]
18+
Get-AzVMSize [-ResourceGroupName] <String> [-VMName] <String> [-DefaultProfile <IAzureContextContainer>]
2119
[<CommonParameters>]
2220
```
2321

@@ -27,36 +25,22 @@ Get-AzVMSize [-ResourceGroupName] <String> [-AvailabilitySetName] <String>
2725
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2826
```
2927

30-
### ListAvailableSizesForVirtualMachine
31-
```
32-
Get-AzVMSize [-ResourceGroupName] <String> [-VMName] <String> [-DefaultProfile <IAzureContextContainer>]
33-
[<CommonParameters>]
34-
```
35-
3628
## DESCRIPTION
3729
The **Get-AzVMSize** cmdlet gets available virtual machine sizes.
3830

39-
**Note**: The **List Virtual Machine Size** parameter set will be deprecated in the next major release (14.0.0) as its API: [Virtual Machine Sizes - List](https://learn.microsoft.com/en-us/rest/api/compute/virtual-machine-sizes/list) is deprecated. For listing available VM sizes by subscription or location, please use instead [Get-AzComputeResourceSku](https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azcomputeresourcesku). Other parameter sets: "List Available Sizes for Availability Set" and "List Available Sizes for Virtual Machine" will continue to be supported.
31+
For listing available VM sizes by subscription or location, use instead [Get-AzComputeResourceSku](https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azcomputeresourcesku).
4032

4133
## EXAMPLES
4234

43-
### Example 1: Get virtual machine sizes for a location
44-
```powershell
45-
Get-AzVMSize -Location "Central US"
46-
```
47-
48-
This command gets the available sizes for virtual machines in the specified location.
49-
50-
**Note**: This parameter set will be deprecated in the next major release.
5135

52-
### Example 2: Get sizes for an availability set
36+
### Example 1: Get sizes for an availability set
5337
```powershell
5438
Get-AzVMSize -ResourceGroupName "ResourceGroup03" -AvailabilitySetName "AvailabilitySet17"
5539
```
5640

5741
This command gets available sizes for virtual machines that you can deploy in the availability set named AvailabilitySet17.
5842

59-
### Example 3: Get sizes for an existing virtual machine
43+
### Example 2: Get sizes for an existing virtual machine
6044
```powershell
6145
Get-AzVMSize -ResourceGroupName "ResourceGroup03" -VMName "VirtualMachine12"
6246
```
@@ -96,27 +80,12 @@ Accept pipeline input: False
9680
Accept wildcard characters: False
9781
```
9882
99-
### -Location
100-
Specifies the location for which this cmdlet gets the available virtual machine sizes.
101-
102-
```yaml
103-
Type: System.String
104-
Parameter Sets: ListVirtualMachineSizeParamSet
105-
Aliases:
106-
107-
Required: True
108-
Position: 0
109-
Default value: None
110-
Accept pipeline input: True (ByPropertyName)
111-
Accept wildcard characters: False
112-
```
113-
11483
### -ResourceGroupName
11584
Specifies the name of the resource group of the virtual machine.
11685
11786
```yaml
11887
Type: System.String
119-
Parameter Sets: ListAvailableSizesForAvailabilitySet, ListAvailableSizesForVirtualMachine
88+
Parameter Sets: (All)
12089
Aliases:
12190

12291
Required: True
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"Module","ClassName","Target","Severity","ProblemId","Description","Remediation"
2+
"Az.Compute","Microsoft.Azure.Commands.Compute.GetAzureVMSizeCommand","Get-AzVMSize","0","1060","The parameter set 'ListVirtualMachineSizeParamSet' for cmdlet 'Get-AzVMSize' is no longer the default parameter set.","Change the default parameter for cmdlet 'Get-AzVMSize' back to 'ListVirtualMachineSizeParamSet'."
3+
"Az.Compute","Microsoft.Azure.Commands.Compute.GetAzureVMSizeCommand","Get-AzVMSize","0","2000","The cmdlet 'Get-AzVMSize' no longer supports the parameter 'Location' and no alias was found for the original parameter name.","Add the parameter 'Location' back to the cmdlet 'Get-AzVMSize', or add an alias to the original parameter name."
4+
"Az.Compute","Microsoft.Azure.Commands.Compute.GetAzureVMSizeCommand","Get-AzVMSize","0","1050","The parameter set 'ListVirtualMachineSizeParamSet' for cmdlet 'Get-AzVMSize' has been removed.","Add parameter set 'ListVirtualMachineSizeParamSet' back to cmdlet 'Get-AzVMSize'."

0 commit comments

Comments
 (0)