|
22 | 22 |
|
23 | 23 | namespace Microsoft.Azure.Commands.Network
|
24 | 24 | {
|
25 |
| - [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkSecurityGroup"), OutputType(typeof(PSNetworkSecurityGroup))] |
| 25 | + [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkSecurityGroup", SupportsShouldProcess = true), OutputType(typeof(PSNetworkSecurityGroup))] |
26 | 26 | public class GetAzureNetworkSecurityGroupCommand : NetworkSecurityGroupBaseCmdlet
|
27 | 27 | {
|
28 | 28 | [Alias("ResourceName")]
|
@@ -63,38 +63,41 @@ public class GetAzureNetworkSecurityGroupCommand : NetworkSecurityGroupBaseCmdle
|
63 | 63 |
|
64 | 64 | public override void Execute()
|
65 | 65 | {
|
66 |
| - base.Execute(); |
67 |
| - if (!string.IsNullOrEmpty(this.Name)) |
| 66 | + if (this.ShouldProcess(Name, VerbsLifecycle.Restart)) |
68 | 67 | {
|
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)) |
77 | 70 | {
|
78 |
| - nsgPage = this.NetworkSecurityGroupClient.List(this.ResourceGroupName); |
| 71 | + var nsg = this.GetNetworkSecurityGroup(this.ResourceGroupName, this.Name, this.ExpandResource); |
| 72 | + |
| 73 | + WriteObject(nsg); |
79 | 74 | }
|
80 | 75 | else
|
81 | 76 | {
|
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 | + } |
84 | 86 |
|
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); |
87 | 89 |
|
88 |
| - var psNsgs = new List<PSNetworkSecurityGroup>(); |
| 90 | + var psNsgs = new List<PSNetworkSecurityGroup>(); |
89 | 91 |
|
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 | + } |
96 | 98 |
|
97 |
| - WriteObject(psNsgs, true); |
| 99 | + WriteObject(psNsgs, true); |
| 100 | + } |
98 | 101 | }
|
99 | 102 | }
|
100 | 103 | }
|
|
0 commit comments