Skip to content

Commit 8b18fce

Browse files
author
Will Ehrich
committed
Update Get-AzureRmNetworkSecurityGroup cmdlet
1 parent 7410c4f commit 8b18fce

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

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

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

2323
namespace Microsoft.Azure.Commands.Network
2424
{
25-
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkSecurityGroup"), OutputType(typeof(PSNetworkSecurityGroup))]
25+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkSecurityGroup", SupportsShouldProcess = true), OutputType(typeof(PSNetworkSecurityGroup))]
2626
public class GetAzureNetworkSecurityGroupCommand : NetworkSecurityGroupBaseCmdlet
2727
{
2828
[Alias("ResourceName")]
@@ -63,38 +63,41 @@ public class GetAzureNetworkSecurityGroupCommand : NetworkSecurityGroupBaseCmdle
6363

6464
public override void Execute()
6565
{
66-
base.Execute();
67-
if (!string.IsNullOrEmpty(this.Name))
66+
if (this.ShouldProcess(Name, VerbsLifecycle.Restart))
6867
{
69-
var nsg = this.GetNetworkSecurityGroup(this.ResourceGroupName, this.Name, this.ExpandResource);
70-
71-
WriteObject(nsg);
72-
}
73-
else
74-
{
75-
IPage<NetworkSecurityGroup> nsgPage;
76-
if (!string.IsNullOrEmpty(this.ResourceGroupName))
68+
base.Execute();
69+
if (!string.IsNullOrEmpty(this.Name))
7770
{
78-
nsgPage = this.NetworkSecurityGroupClient.List(this.ResourceGroupName);
71+
var nsg = this.GetNetworkSecurityGroup(this.ResourceGroupName, this.Name, this.ExpandResource);
72+
73+
WriteObject(nsg);
7974
}
8075
else
8176
{
82-
nsgPage = this.NetworkSecurityGroupClient.ListAll();
83-
}
77+
IPage<NetworkSecurityGroup> nsgPage;
78+
if (!string.IsNullOrEmpty(this.ResourceGroupName))
79+
{
80+
nsgPage = this.NetworkSecurityGroupClient.List(this.ResourceGroupName);
81+
}
82+
else
83+
{
84+
nsgPage = this.NetworkSecurityGroupClient.ListAll();
85+
}
8486

85-
// Get all resources by polling on next page link
86-
var nsgList = ListNextLink<NetworkSecurityGroup>.GetAllResourcesByPollingNextLink(nsgPage, this.NetworkSecurityGroupClient.ListNext);
87+
// Get all resources by polling on next page link
88+
var nsgList = ListNextLink<NetworkSecurityGroup>.GetAllResourcesByPollingNextLink(nsgPage, this.NetworkSecurityGroupClient.ListNext);
8789

88-
var psNsgs = new List<PSNetworkSecurityGroup>();
90+
var psNsgs = new List<PSNetworkSecurityGroup>();
8991

90-
foreach (var networkSecurityGroup in nsgList)
91-
{
92-
var psNsg = this.ToPsNetworkSecurityGroup(networkSecurityGroup);
93-
psNsg.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkSecurityGroup.Id);
94-
psNsgs.Add(psNsg);
95-
}
92+
foreach (var networkSecurityGroup in nsgList)
93+
{
94+
var psNsg = this.ToPsNetworkSecurityGroup(networkSecurityGroup);
95+
psNsg.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkSecurityGroup.Id);
96+
psNsgs.Add(psNsg);
97+
}
9698

97-
WriteObject(psNsgs, true);
99+
WriteObject(psNsgs, true);
100+
}
98101
}
99102
}
100103
}

0 commit comments

Comments
 (0)