Skip to content

Commit 9b42fa4

Browse files
authored
Merge pull request Azure#7308 from wdehrich/whatIfSupport
What if support
2 parents f889a07 + cb4b372 commit 9b42fa4

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

src/ResourceManager/Network/Commands.Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--->
2020

2121
## Current Release
22+
* Added WhatIf support to Set-AzureRmNetworkSecurityGroup
2223

2324
## Version 6.8.0
2425
* Replaced LoadBalancer cmdlets with generated code

src/ResourceManager/Network/Commands.Network/NetworkSecurityGroup/SetAzureNetworkSecurityGroupCommand.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace Microsoft.Azure.Commands.Network
2424
{
25-
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkSecurityGroup"), OutputType(typeof(PSNetworkSecurityGroup))]
25+
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkSecurityGroup", SupportsShouldProcess = true), OutputType(typeof(PSNetworkSecurityGroup))]
2626
public class SetAzureNetworkSecurityGroupCommand : NetworkSecurityGroupBaseCmdlet
2727
{
2828
[Parameter(
@@ -36,25 +36,28 @@ public class SetAzureNetworkSecurityGroupCommand : NetworkSecurityGroupBaseCmdle
3636

3737
public override void Execute()
3838
{
39-
base.Execute();
40-
41-
if (!this.IsNetworkSecurityGroupPresent(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name))
39+
if (this.ShouldProcess(NetworkSecurityGroup.Name, VerbsLifecycle.Restart))
4240
{
43-
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
44-
}
41+
base.Execute();
4542

46-
// Map to the sdk object
47-
var nsgModel = NetworkResourceManagerProfile.Mapper.Map<MNM.NetworkSecurityGroup>(this.NetworkSecurityGroup);
43+
if (!this.IsNetworkSecurityGroupPresent(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name))
44+
{
45+
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
46+
}
4847

49-
this.NullifyApplicationSecurityGroupsIfAbsent(nsgModel);
48+
// Map to the sdk object
49+
var nsgModel = NetworkResourceManagerProfile.Mapper.Map<MNM.NetworkSecurityGroup>(this.NetworkSecurityGroup);
5050

51-
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkSecurityGroup.Tag, validate: true);
51+
this.NullifyApplicationSecurityGroupsIfAbsent(nsgModel);
5252

53-
// Execute the PUT NetworkSecurityGroup call
54-
this.NetworkSecurityGroupClient.CreateOrUpdate(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name, nsgModel);
53+
nsgModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkSecurityGroup.Tag, validate: true);
5554

56-
var getNetworkSecurityGroup = this.GetNetworkSecurityGroup(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name);
57-
WriteObject(getNetworkSecurityGroup);
55+
// Execute the PUT NetworkSecurityGroup call
56+
this.NetworkSecurityGroupClient.CreateOrUpdate(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name, nsgModel);
57+
58+
var getNetworkSecurityGroup = this.GetNetworkSecurityGroup(this.NetworkSecurityGroup.ResourceGroupName, this.NetworkSecurityGroup.Name);
59+
WriteObject(getNetworkSecurityGroup);
60+
}
5861
}
5962
}
6063
}

src/ResourceManager/Network/Commands.Network/help/Set-AzureRmNetworkSecurityGroup.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Sets the goal state for a network security group.
1515

1616
```
1717
Set-AzureRmNetworkSecurityGroup -NetworkSecurityGroup <PSNetworkSecurityGroup> [-AsJob]
18-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
18+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
@@ -78,6 +78,36 @@ Accept pipeline input: True (ByValue)
7878
Accept wildcard characters: False
7979
```
8080
81+
### -Confirm
82+
Prompts you for confirmation before running the cmdlet.
83+
84+
```yaml
85+
Type: System.Management.Automation.SwitchParameter
86+
Parameter Sets: (All)
87+
Aliases: cf
88+
89+
Required: False
90+
Position: Named
91+
Default value: None
92+
Accept pipeline input: False
93+
Accept wildcard characters: False
94+
```
95+
96+
### -WhatIf
97+
Shows what would happen if the cmdlet runs. The cmdlet is not run.
98+
99+
```yaml
100+
Type: System.Management.Automation.SwitchParameter
101+
Parameter Sets: (All)
102+
Aliases: wi
103+
104+
Required: False
105+
Position: Named
106+
Default value: None
107+
Accept pipeline input: False
108+
Accept wildcard characters: False
109+
```
110+
81111
### CommonParameters
82112
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
83113

0 commit comments

Comments
 (0)