Skip to content

Commit 107303f

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#6097 from AMoghrabi/fix-get-traffic-manager-profile
Fix Get-AzureRmTrafficManagerProfile when calling with -Name Parameter Only (Issue Azure#2342)
2 parents e2ba0e7 + 7fdb959 commit 107303f

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

src/ResourceManager/TrafficManager/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Update the parameters for `Get-AzureRmTrafficManagerProfile` so that -ResourceGroupName parameter is required when using -Name parameter.
2122

2223
## Version 4.0.4
2324
* Set minimum dependency of module to PowerShell 5.0

src/ResourceManager/TrafficManager/Commands.TrafficManager2/Profile/GetAzureTrafficManagerProfile.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,37 @@ namespace Microsoft.Azure.Commands.TrafficManager
2323
[Cmdlet(VerbsCommon.Get, "AzureRmTrafficManagerProfile"), OutputType(typeof(TrafficManagerProfile))]
2424
public class GetAzureTrafficManagerProfile : TrafficManagerBaseCmdlet
2525
{
26-
[Parameter(Mandatory = false, HelpMessage = "The name of the profile.")]
27-
[ValidateNotNullOrEmpty]
28-
public string Name { get; set; }
26+
protected const string ResourceGroupParameterSet = "ResourceGroupParameterSet";
27+
protected const string AccountNameParameterSet = "AccountNameParameterSet";
2928

30-
[Parameter(Mandatory = false, HelpMessage = "The resource group to which the profile belongs.")]
29+
[Parameter(
30+
Position = 0,
31+
Mandatory = false,
32+
ParameterSetName = ResourceGroupParameterSet,
33+
ValueFromPipelineByPropertyName = true,
34+
HelpMessage = "The resource group to which the profile belongs.")]
35+
[Parameter(
36+
Position = 0,
37+
Mandatory = true,
38+
ParameterSetName = AccountNameParameterSet,
39+
ValueFromPipelineByPropertyName = true,
40+
HelpMessage = "The resource group to which the profile belongs.")]
3141
[ResourceGroupCompleter]
3242
[ValidateNotNullOrEmpty]
3343
public string ResourceGroupName { get; set; }
3444

45+
[Parameter(
46+
Position = 1,
47+
Mandatory = true,
48+
ValueFromPipelineByPropertyName = true,
49+
ParameterSetName = AccountNameParameterSet,
50+
HelpMessage = "The name of the profile.")]
51+
[ValidateNotNullOrEmpty]
52+
public string Name { get; set; }
53+
3554
public override void ExecuteCmdlet()
3655
{
37-
if (this.ResourceGroupName == null && this.Name != null)
38-
{
39-
// Throw an error
40-
}
41-
else if (this.ResourceGroupName != null && this.Name != null)
56+
if (this.ResourceGroupName != null && this.Name != null)
4257
{
4358
TrafficManagerProfile profile = this.TrafficManagerClient.GetTrafficManagerProfile(this.ResourceGroupName, this.Name);
4459

src/ResourceManager/TrafficManager/Commands.TrafficManager2/help/Get-AzureRmTrafficManagerProfile.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
---
1+
---
22
external help file: Microsoft.Azure.Commands.TrafficManager.dll-Help.xml
3-
Module Name: AzureRM
3+
Module Name: AzureRM.TrafficManager
44
ms.assetid: 5032D487-3849-4C80-BD14-5B735FC39285
55
online version: https://docs.microsoft.com/en-us/powershell/module/azurerm.trafficmanager/get-azurermtrafficmanagerprofile
66
schema: 2.0.0
@@ -13,8 +13,15 @@ Gets a Traffic Manager profile.
1313

1414
## SYNTAX
1515

16+
### ResourceGroupParameterSet
17+
```
18+
Get-AzureRmTrafficManagerProfile [[-ResourceGroupName] <String>] [-DefaultProfile <IAzureContextContainer>]
19+
[<CommonParameters>]
1620
```
17-
Get-AzureRmTrafficManagerProfile [-Name <String>] [-ResourceGroupName <String>]
21+
22+
### AccountNameParameterSet
23+
```
24+
Get-AzureRmTrafficManagerProfile [-ResourceGroupName] <String> [-Name] <String>
1825
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1926
```
2027

@@ -55,13 +62,13 @@ Specifies the name of the Traffic Manager profile that this cmdlet gets.
5562
5663
```yaml
5764
Type: String
58-
Parameter Sets: (All)
59-
Aliases:
65+
Parameter Sets: AccountNameParameterSet
66+
Aliases:
6067

61-
Required: False
62-
Position: Named
68+
Required: True
69+
Position: 1
6370
Default value: None
64-
Accept pipeline input: False
71+
Accept pipeline input: True (ByPropertyName)
6572
Accept wildcard characters: False
6673
```
6774
@@ -70,13 +77,25 @@ Specifies the name of a resource group that contains the Traffic Manager profile
7077
7178
```yaml
7279
Type: String
73-
Parameter Sets: (All)
74-
Aliases:
80+
Parameter Sets: ResourceGroupParameterSet
81+
Aliases:
7582

7683
Required: False
77-
Position: Named
84+
Position: 0
7885
Default value: None
79-
Accept pipeline input: False
86+
Accept pipeline input: True (ByPropertyName)
87+
Accept wildcard characters: False
88+
```
89+
90+
```yaml
91+
Type: String
92+
Parameter Sets: AccountNameParameterSet
93+
Aliases:
94+
95+
Required: True
96+
Position: 0
97+
Default value: None
98+
Accept pipeline input: True (ByPropertyName)
8099
Accept wildcard characters: False
81100
```
82101

tools/StaticAnalysis/Exceptions/BreakingChangeIssues.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,4 +1603,5 @@
16031603
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand","New-AzureRmVirtualNetwork","0","3010","The property 'EnableDDoSProtection' of type 'Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork' has been removed.","Add the property 'EnableDDoSProtection' back to type 'Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork'."
16041604
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand","New-AzureRmVirtualNetwork","0","3010","The property 'EnableDDoSProtectionText' of type 'Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork' has been removed.","Add the property 'EnableDDoSProtectionText' back to type 'Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork'."
16051605
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand","New-AzureRmVirtualNetwork","0","2000","The cmdlet 'New-AzureRmVirtualNetwork' no longer supports the parameter 'EnableDDoSProtection' and no alias was found for the original parameter name.","Add the parameter 'EnableDDoSProtection' back to the cmdlet 'New-AzureRmVirtualNetwork', or add an alias to the original parameter name."
1606-
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand","New-AzureRmVirtualNetwork","0","1050","The parameter set '__AllParameterSets' for cmdlet 'New-AzureRmVirtualNetwork' has been removed.","Add parameter set '__AllParameterSets' back to cmdlet 'New-AzureRmVirtualNetwork'."
1606+
"Microsoft.Azure.Commands.Network.dll","Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand","New-AzureRmVirtualNetwork","0","1050","The parameter set '__AllParameterSets' for cmdlet 'New-AzureRmVirtualNetwork' has been removed.","Add parameter set '__AllParameterSets' back to cmdlet 'New-AzureRmVirtualNetwork'."
1607+
"Microsoft.Azure.Commands.TrafficManager.dll","Microsoft.Azure.Commands.TrafficManager.GetAzureTrafficManagerProfile","Get-AzureRmTrafficManagerProfile","0","1050","The parameter set '__AllParameterSets' for cmdlet 'Get-AzureRmTrafficManagerProfile' has been removed.","Add parameter set '__AllParameterSets' back to cmdlet 'Get-AzureRmTrafficManagerProfile'."

0 commit comments

Comments
 (0)