Skip to content

Commit f6305d2

Browse files
committed
Add ShouldProcess support to Remove-AzureRmVMSecret, Remove-AzureRmVMNetworkInterface and Remove-AzureRmVMDataDisk cmdlets
1 parent 4298129 commit f6305d2

File tree

4 files changed

+166
-52
lines changed

4 files changed

+166
-52
lines changed

src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.dll-Help.xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9351,6 +9351,22 @@ PS C:\> Remove-AzureRmContainerServiceAgentPoolProfile -ContainerService $Con
93519351
<maml:uri /></dev:type>
93529352
<dev:defaultValue>None</dev:defaultValue>
93539353
</command:parameter>
9354+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf"><maml:name>Confirm</maml:name>
9355+
<maml:Description><maml:para>Prompts you for confirmation before running the cmdlet.
9356+
</maml:para>
9357+
</maml:Description>
9358+
<dev:type><maml:name>SwitchParameter</maml:name>
9359+
<maml:uri /></dev:type>
9360+
<dev:defaultValue>False</dev:defaultValue>
9361+
</command:parameter>
9362+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"><maml:name>WhatIf</maml:name>
9363+
<maml:Description><maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.
9364+
</maml:para>
9365+
</maml:Description>
9366+
<dev:type><maml:name>SwitchParameter</maml:name>
9367+
<maml:uri /></dev:type>
9368+
<dev:defaultValue>False</dev:defaultValue>
9369+
</command:parameter>
93549370
</command:syntaxItem>
93559371
</command:syntax>
93569372
<command:parameters><command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="2" aliases="Name"><maml:name>DataDiskNames</maml:name>
@@ -9371,6 +9387,24 @@ PS C:\&gt; Remove-AzureRmContainerServiceAgentPoolProfile -ContainerService $Con
93719387
<maml:uri /></dev:type>
93729388
<dev:defaultValue>None</dev:defaultValue>
93739389
</command:parameter>
9390+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf"><maml:name>Confirm</maml:name>
9391+
<maml:Description><maml:para>Prompts you for confirmation before running the cmdlet.
9392+
</maml:para>
9393+
</maml:Description>
9394+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
9395+
<dev:type><maml:name>SwitchParameter</maml:name>
9396+
<maml:uri /></dev:type>
9397+
<dev:defaultValue>False</dev:defaultValue>
9398+
</command:parameter>
9399+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"><maml:name>WhatIf</maml:name>
9400+
<maml:Description><maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.
9401+
</maml:para>
9402+
</maml:Description>
9403+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
9404+
<dev:type><maml:name>SwitchParameter</maml:name>
9405+
<maml:uri /></dev:type>
9406+
<dev:defaultValue>False</dev:defaultValue>
9407+
</command:parameter>
93749408
</command:parameters>
93759409
<command:inputTypes></command:inputTypes>
93769410
<command:returnValues></command:returnValues>
@@ -9946,6 +9980,22 @@ PS C:\&gt; Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualM
99469980
<maml:uri /></dev:type>
99479981
<dev:defaultValue>None</dev:defaultValue>
99489982
</command:parameter>
9983+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf"><maml:name>Confirm</maml:name>
9984+
<maml:Description><maml:para>Prompts you for confirmation before running the cmdlet.
9985+
</maml:para>
9986+
</maml:Description>
9987+
<dev:type><maml:name>SwitchParameter</maml:name>
9988+
<maml:uri /></dev:type>
9989+
<dev:defaultValue>False</dev:defaultValue>
9990+
</command:parameter>
9991+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"><maml:name>WhatIf</maml:name>
9992+
<maml:Description><maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.
9993+
</maml:para>
9994+
</maml:Description>
9995+
<dev:type><maml:name>SwitchParameter</maml:name>
9996+
<maml:uri /></dev:type>
9997+
<dev:defaultValue>False</dev:defaultValue>
9998+
</command:parameter>
99499999
</command:syntaxItem>
995010000
</command:syntax>
995110001
<command:parameters><command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="2" aliases="Id, NicIds"><maml:name>NetworkInterfaceIDs</maml:name>
@@ -9966,6 +10016,24 @@ PS C:\&gt; Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualM
996610016
<maml:uri /></dev:type>
996710017
<dev:defaultValue>None</dev:defaultValue>
996810018
</command:parameter>
10019+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf"><maml:name>Confirm</maml:name>
10020+
<maml:Description><maml:para>Prompts you for confirmation before running the cmdlet.
10021+
</maml:para>
10022+
</maml:Description>
10023+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
10024+
<dev:type><maml:name>SwitchParameter</maml:name>
10025+
<maml:uri /></dev:type>
10026+
<dev:defaultValue>False</dev:defaultValue>
10027+
</command:parameter>
10028+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"><maml:name>WhatIf</maml:name>
10029+
<maml:Description><maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.
10030+
</maml:para>
10031+
</maml:Description>
10032+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
10033+
<dev:type><maml:name>SwitchParameter</maml:name>
10034+
<maml:uri /></dev:type>
10035+
<dev:defaultValue>False</dev:defaultValue>
10036+
</command:parameter>
996910037
</command:parameters>
997010038
<command:inputTypes></command:inputTypes>
997110039
<command:returnValues></command:returnValues>
@@ -10017,6 +10085,22 @@ PS C:\&gt; Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualM
1001710085
<maml:uri /></dev:type>
1001810086
<dev:defaultValue>None</dev:defaultValue>
1001910087
</command:parameter>
10088+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf"><maml:name>Confirm</maml:name>
10089+
<maml:Description><maml:para>Prompts you for confirmation before running the cmdlet.
10090+
</maml:para>
10091+
</maml:Description>
10092+
<dev:type><maml:name>SwitchParameter</maml:name>
10093+
<maml:uri /></dev:type>
10094+
<dev:defaultValue>False</dev:defaultValue>
10095+
</command:parameter>
10096+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"><maml:name>WhatIf</maml:name>
10097+
<maml:Description><maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.
10098+
</maml:para>
10099+
</maml:Description>
10100+
<dev:type><maml:name>SwitchParameter</maml:name>
10101+
<maml:uri /></dev:type>
10102+
<dev:defaultValue>False</dev:defaultValue>
10103+
</command:parameter>
1002010104
</command:syntaxItem>
1002110105
</command:syntax>
1002210106
<command:parameters><command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="Id"><maml:name>SourceVaultId</maml:name>
@@ -10037,6 +10121,24 @@ PS C:\&gt; Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualM
1003710121
<maml:uri /></dev:type>
1003810122
<dev:defaultValue>None</dev:defaultValue>
1003910123
</command:parameter>
10124+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf"><maml:name>Confirm</maml:name>
10125+
<maml:Description><maml:para>Prompts you for confirmation before running the cmdlet.
10126+
</maml:para>
10127+
</maml:Description>
10128+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
10129+
<dev:type><maml:name>SwitchParameter</maml:name>
10130+
<maml:uri /></dev:type>
10131+
<dev:defaultValue>False</dev:defaultValue>
10132+
</command:parameter>
10133+
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"><maml:name>WhatIf</maml:name>
10134+
<maml:Description><maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.
10135+
</maml:para>
10136+
</maml:Description>
10137+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
10138+
<dev:type><maml:name>SwitchParameter</maml:name>
10139+
<maml:uri /></dev:type>
10140+
<dev:defaultValue>False</dev:defaultValue>
10141+
</command:parameter>
1004010142
</command:parameters>
1004110143
<command:inputTypes><command:inputType><dev:type><maml:name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine</maml:name>
1004210144
</dev:type>

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Microsoft.Azure.Commands.Compute
2222
{
2323
[Cmdlet(
2424
VerbsCommon.Remove,
25-
ProfileNouns.DataDisk),
25+
ProfileNouns.DataDisk,
26+
SupportsShouldProcess = true),
2627
OutputType(
2728
typeof(PSVirtualMachine))]
2829
public class RemoveAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
@@ -47,30 +48,33 @@ public class RemoveAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceMan
4748

4849
public override void ExecuteCmdlet()
4950
{
50-
var storageProfile = this.VM.StorageProfile;
51-
52-
if (storageProfile != null && storageProfile.DataDisks != null)
51+
if (this.ShouldProcess("DataDisk", VerbsCommon.Remove))
5352
{
54-
var disks = storageProfile.DataDisks.ToList();
55-
var comp = StringComparison.OrdinalIgnoreCase;
53+
var storageProfile = this.VM.StorageProfile;
5654

57-
if (DataDiskNames == null)
58-
{
59-
disks.Clear();
60-
}
61-
else
55+
if (storageProfile != null && storageProfile.DataDisks != null)
6256
{
63-
foreach (var diskName in DataDiskNames)
57+
var disks = storageProfile.DataDisks.ToList();
58+
var comp = StringComparison.OrdinalIgnoreCase;
59+
60+
if (DataDiskNames == null)
6461
{
65-
disks.RemoveAll(d => string.Equals(d.Name, diskName, comp));
62+
disks.Clear();
6663
}
64+
else
65+
{
66+
foreach (var diskName in DataDiskNames)
67+
{
68+
disks.RemoveAll(d => string.Equals(d.Name, diskName, comp));
69+
}
70+
}
71+
storageProfile.DataDisks = disks;
6772
}
68-
storageProfile.DataDisks = disks;
69-
}
7073

71-
this.VM.StorageProfile = storageProfile;
74+
this.VM.StorageProfile = storageProfile;
7275

73-
WriteObject(this.VM);
76+
WriteObject(this.VM);
77+
}
7478
}
7579
}
7680
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace Microsoft.Azure.Commands.Compute
2525
/// </summary>
2626
[Cmdlet(
2727
VerbsCommon.Remove,
28-
ProfileNouns.NetworkInterface),
28+
ProfileNouns.NetworkInterface,
29+
SupportsShouldProcess = true),
2930
OutputType(
3031
typeof(PSVirtualMachine))]
3132
public class RemoveAzureVMNetworkInterfaceCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
@@ -50,30 +51,33 @@ public class RemoveAzureVMNetworkInterfaceCommand : Microsoft.Azure.Commands.Res
5051

5152
public override void ExecuteCmdlet()
5253
{
53-
var networkProfile = this.VM.NetworkProfile;
54-
55-
if (NetworkInterfaceIDs == null)
56-
{
57-
networkProfile.NetworkInterfaces.Clear();
58-
}
59-
else
54+
if (this.ShouldProcess("NetworkInterface", VerbsCommon.Remove))
6055
{
61-
foreach (var id in this.NetworkInterfaceIDs)
56+
var networkProfile = this.VM.NetworkProfile;
57+
58+
if (NetworkInterfaceIDs == null)
6259
{
63-
if (networkProfile != null &&
64-
networkProfile.NetworkInterfaces != null &&
65-
networkProfile.NetworkInterfaces.Any(nic =>
66-
string.Equals(nic.Id, id, StringComparison.OrdinalIgnoreCase)))
60+
networkProfile.NetworkInterfaces.Clear();
61+
}
62+
else
63+
{
64+
foreach (var id in this.NetworkInterfaceIDs)
6765
{
68-
var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.Id, id, StringComparison.OrdinalIgnoreCase));
69-
networkProfile.NetworkInterfaces.Remove(nicReference);
66+
if (networkProfile != null &&
67+
networkProfile.NetworkInterfaces != null &&
68+
networkProfile.NetworkInterfaces.Any(nic =>
69+
string.Equals(nic.Id, id, StringComparison.OrdinalIgnoreCase)))
70+
{
71+
var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.Id, id, StringComparison.OrdinalIgnoreCase));
72+
networkProfile.NetworkInterfaces.Remove(nicReference);
73+
}
7074
}
7175
}
72-
}
7376

74-
this.VM.NetworkProfile = networkProfile;
77+
this.VM.NetworkProfile = networkProfile;
7578

76-
WriteObject(this.VM);
79+
WriteObject(this.VM);
80+
}
7781
}
7882
}
7983
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMSecretCommand.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Microsoft.Azure.Commands.Compute
2222
{
2323
[Cmdlet(
2424
VerbsCommon.Remove,
25-
ProfileNouns.VaultSecretGroup),
25+
ProfileNouns.VaultSecretGroup,
26+
SupportsShouldProcess = true),
2627
OutputType(
2728
typeof(PSVirtualMachine))]
2829
public class RemoveAzureVMSecretCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
@@ -46,30 +47,33 @@ public class RemoveAzureVMSecretCommand : Microsoft.Azure.Commands.ResourceManag
4647

4748
public override void ExecuteCmdlet()
4849
{
49-
var osProfile = this.VM.OSProfile;
50-
51-
if (osProfile != null && osProfile.Secrets != null)
50+
if (this.ShouldProcess("SourceVault", VerbsCommon.Remove))
5251
{
53-
var secrets = osProfile.Secrets.ToList();
54-
var comp = StringComparison.OrdinalIgnoreCase;
52+
var osProfile = this.VM.OSProfile;
5553

56-
if (this.SourceVaultId == null)
57-
{
58-
secrets.Clear();
59-
}
60-
else
54+
if (osProfile != null && osProfile.Secrets != null)
6155
{
62-
foreach (var id in this.SourceVaultId)
56+
var secrets = osProfile.Secrets.ToList();
57+
var comp = StringComparison.OrdinalIgnoreCase;
58+
59+
if (this.SourceVaultId == null)
6360
{
64-
secrets.RemoveAll(d => string.Equals(d.SourceVault.Id, id, comp));
61+
secrets.Clear();
6562
}
63+
else
64+
{
65+
foreach (var id in this.SourceVaultId)
66+
{
67+
secrets.RemoveAll(d => string.Equals(d.SourceVault.Id, id, comp));
68+
}
69+
}
70+
osProfile.Secrets = secrets;
6671
}
67-
osProfile.Secrets = secrets;
68-
}
6972

70-
this.VM.OSProfile = osProfile;
73+
this.VM.OSProfile = osProfile;
7174

72-
WriteObject(this.VM);
75+
WriteObject(this.VM);
76+
}
7377
}
7478
}
7579
}

0 commit comments

Comments
 (0)