Skip to content

Commit 53d2a11

Browse files
authored
Merge pull request #5889 from hyonholee/disable
Add DisableVMAgent parameter to Set-AzureRmVMOperatingSystem cmdlet
2 parents ffb67e3 + e88acb4 commit 53d2a11

File tree

4 files changed

+122
-7
lines changed

4 files changed

+122
-7
lines changed

src/ResourceManager/Compute/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+
* Add DisableVMAgent switch parameter to `Set-AzureRmVMOperatingSystem` cmdlet
2122
* `New-AzureRmVm` and `New-AzureRmVmss` (simple parameter set) support a `Win10` image.
2223
* `Repair-AzureRmVmssServiceFabricUpdateDomain` cmdlet is added.
2324
* Set minimum dependency of module to PowerShell 5.0

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,13 @@ function Test-VirtualMachineProfileWithoutAUC
399399
# Verify Additional Unattend Content
400400
Assert-Null $p.OSProfile.WindowsConfiguration.AdditionalUnattendContent "NULL";
401401
Assert-False {$p.OSProfile.WindowsConfiguration.AdditionalUnattendContent.IsInitialized};
402+
403+
$p.OSProfile = $null;
404+
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
405+
Assert-Null $p.OSProfile.WindowsConfiguration.ProvisionVMAgent;
406+
407+
$p.OSProfile = $null;
408+
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -DisableVMAgent;
409+
Assert-False {$p.OSProfile.WindowsConfiguration.ProvisionVMAgent};
410+
402411
}

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
3636
{
3737
protected const string WindowsParamSet = "Windows";
3838
protected const string WinRmHttpsParamSet = "WindowsWinRmHttps";
39+
protected const string WindowsDisableVMAgentParamSet = "WindowsDisableVMAgent";
40+
protected const string WindowsDisableVMAgentWinRmHttpsParamSet = "WindowsDisableVMAgentWinRmHttps";
3941
protected const string LinuxParamSet = "Linux";
4042

4143
[Alias("VMProfile")]
@@ -60,6 +62,18 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
6062
Position = 1,
6163
ValueFromPipelineByPropertyName = true,
6264
HelpMessage = "Windows")]
65+
[Parameter(
66+
ParameterSetName = WindowsDisableVMAgentParamSet,
67+
Mandatory = true,
68+
Position = 1,
69+
ValueFromPipelineByPropertyName = true,
70+
HelpMessage = "Windows")]
71+
[Parameter(
72+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
73+
Mandatory = true,
74+
Position = 1,
75+
ValueFromPipelineByPropertyName = true,
76+
HelpMessage = "Windows")]
6377
[ValidateNotNullOrEmpty]
6478
public SwitchParameter Windows { get; set; }
6579

@@ -108,6 +122,15 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
108122
[ValidateNotNullOrEmpty]
109123
public SwitchParameter ProvisionVMAgent { get; set; }
110124

125+
[Parameter(
126+
ParameterSetName = WindowsDisableVMAgentParamSet,
127+
HelpMessage = "Disable Provision VM Agent.")]
128+
[Parameter(
129+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
130+
HelpMessage = "Disable Provision VM Agent.")]
131+
[ValidateNotNullOrEmpty]
132+
public SwitchParameter DisableVMAgent { get; set; }
133+
111134
[Parameter(
112135
ParameterSetName = WindowsParamSet,
113136
Position = 6,
@@ -118,6 +141,16 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
118141
Position = 6,
119142
ValueFromPipelineByPropertyName = true,
120143
HelpMessage = "Enable Automatic Update")]
144+
[Parameter(
145+
ParameterSetName = WindowsDisableVMAgentParamSet,
146+
Position = 6,
147+
ValueFromPipelineByPropertyName = true,
148+
HelpMessage = "Enable Automatic Update")]
149+
[Parameter(
150+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
151+
Position = 6,
152+
ValueFromPipelineByPropertyName = true,
153+
HelpMessage = "Enable Automatic Update")]
121154
[ValidateNotNullOrEmpty]
122155
public SwitchParameter EnableAutoUpdate { get; set; }
123156

@@ -131,6 +164,16 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
131164
Position = 7,
132165
ValueFromPipelineByPropertyName = true,
133166
HelpMessage = "Time Zone")]
167+
[Parameter(
168+
ParameterSetName = WindowsDisableVMAgentParamSet,
169+
Position = 7,
170+
ValueFromPipelineByPropertyName = true,
171+
HelpMessage = "Time Zone")]
172+
[Parameter(
173+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
174+
Position = 7,
175+
ValueFromPipelineByPropertyName = true,
176+
HelpMessage = "Time Zone")]
134177
[ValidateNotNullOrEmpty]
135178
public string TimeZone { get; set; }
136179

@@ -144,6 +187,16 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
144187
Position = 8,
145188
ValueFromPipelineByPropertyName = true,
146189
HelpMessage = "Enable WinRM Http protocol")]
190+
[Parameter(
191+
ParameterSetName = WindowsDisableVMAgentParamSet,
192+
Position = 8,
193+
ValueFromPipelineByPropertyName = true,
194+
HelpMessage = "Enable WinRM Http protocol")]
195+
[Parameter(
196+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
197+
Position = 8,
198+
ValueFromPipelineByPropertyName = true,
199+
HelpMessage = "Enable WinRM Http protocol")]
147200
[ValidateNotNullOrEmpty]
148201
public SwitchParameter WinRMHttp { get; set; }
149202

@@ -153,6 +206,12 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
153206
Position = 9,
154207
ValueFromPipelineByPropertyName = true,
155208
HelpMessage = "Enable WinRM Https protocol")]
209+
[Parameter(
210+
Mandatory = true,
211+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
212+
Position = 9,
213+
ValueFromPipelineByPropertyName = true,
214+
HelpMessage = "Enable WinRM Https protocol")]
156215
[ValidateNotNullOrEmpty]
157216
public SwitchParameter WinRMHttps { get; set; }
158217

@@ -162,6 +221,12 @@ public class SetAzureVMOperatingSystemCommand : Microsoft.Azure.Commands.Resourc
162221
Position = 10,
163222
ValueFromPipelineByPropertyName = true,
164223
HelpMessage = "Url for WinRM certificate")]
224+
[Parameter(
225+
Mandatory = true,
226+
ParameterSetName = WindowsDisableVMAgentWinRmHttpsParamSet,
227+
Position = 10,
228+
ValueFromPipelineByPropertyName = true,
229+
HelpMessage = "Url for WinRM certificate")]
165230
[ValidateNotNullOrEmpty]
166231
public Uri WinRMCertificateUrl { get; set; }
167232

@@ -235,7 +300,17 @@ public override void ExecuteCmdlet()
235300
}
236301

237302
// OS Profile
238-
this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = this.ProvisionVMAgent.IsPresent;
303+
this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent;
304+
305+
if (this.ProvisionVMAgent.IsPresent)
306+
{
307+
this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = true;
308+
}
309+
310+
if (this.DisableVMAgent.IsPresent)
311+
{
312+
this.VM.OSProfile.WindowsConfiguration.ProvisionVMAgent = false;
313+
}
239314

240315
this.VM.OSProfile.WindowsConfiguration.EnableAutomaticUpdates = this.EnableAutoUpdate.IsPresent;
241316

src/ResourceManager/Compute/Commands.Compute/help/Set-AzureRmVMOperatingSystem.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ Set-AzureRmVMOperatingSystem [-VM] <PSVirtualMachine> [-Windows] [-ComputerName]
2828
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2929
```
3030

31+
### WindowsDisableVMAgent
32+
```
33+
Set-AzureRmVMOperatingSystem [-VM] <PSVirtualMachine> [-Windows] [-ComputerName] <String>
34+
[-Credential] <PSCredential> [[-CustomData] <String>] [-DisableVMAgent] [-EnableAutoUpdate]
35+
[[-TimeZone] <String>] [-WinRMHttp] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
36+
```
37+
38+
### WindowsDisableVMAgentWinRmHttps
39+
```
40+
Set-AzureRmVMOperatingSystem [-VM] <PSVirtualMachine> [-Windows] [-ComputerName] <String>
41+
[-Credential] <PSCredential> [[-CustomData] <String>] [-DisableVMAgent] [-EnableAutoUpdate]
42+
[[-TimeZone] <String>] [-WinRMHttp] [-WinRMHttps] [-WinRMCertificateUrl] <Uri>
43+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
44+
```
45+
3146
### Linux
3247
```
3348
Set-AzureRmVMOperatingSystem [-VM] <PSVirtualMachine> [-Linux] [-ComputerName] <String>
@@ -155,12 +170,27 @@ Accept pipeline input: True (ByPropertyName)
155170
Accept wildcard characters: False
156171
```
157172

173+
### -DisableVMAgent
174+
Disable Provision VM Agent.
175+
176+
```yaml
177+
Type: SwitchParameter
178+
Parameter Sets: WindowsDisableVMAgent, WindowsDisableVMAgentWinRmHttps
179+
Aliases:
180+
181+
Required: False
182+
Position: Named
183+
Default value: None
184+
Accept pipeline input: False
185+
Accept wildcard characters: False
186+
```
187+
158188
### -EnableAutoUpdate
159189
Indicates that this cmdlet enables auto update.
160190

161191
```yaml
162192
Type: SwitchParameter
163-
Parameter Sets: Windows, WindowsWinRmHttps
193+
Parameter Sets: Windows, WindowsWinRmHttps, WindowsDisableVMAgent, WindowsDisableVMAgentWinRmHttps
164194
Aliases:
165195
166196
Required: False
@@ -205,7 +235,7 @@ Specifies the time zone for the virtual machine.
205235

206236
```yaml
207237
Type: String
208-
Parameter Sets: Windows, WindowsWinRmHttps
238+
Parameter Sets: Windows, WindowsWinRmHttps, WindowsDisableVMAgent, WindowsDisableVMAgentWinRmHttps
209239
Aliases:
210240
211241
Required: False
@@ -237,7 +267,7 @@ Indicates that the type of operating system is Windows.
237267

238268
```yaml
239269
Type: SwitchParameter
240-
Parameter Sets: Windows, WindowsWinRmHttps
270+
Parameter Sets: Windows, WindowsWinRmHttps, WindowsDisableVMAgent, WindowsDisableVMAgentWinRmHttps
241271
Aliases:
242272
243273
Required: True
@@ -253,7 +283,7 @@ This needs to be stored in a Key Vault.
253283

254284
```yaml
255285
Type: Uri
256-
Parameter Sets: WindowsWinRmHttps
286+
Parameter Sets: WindowsWinRmHttps, WindowsDisableVMAgentWinRmHttps
257287
Aliases:
258288
259289
Required: True
@@ -268,7 +298,7 @@ Indicates that this operating system uses HTTP WinRM.
268298

269299
```yaml
270300
Type: SwitchParameter
271-
Parameter Sets: Windows, WindowsWinRmHttps
301+
Parameter Sets: Windows, WindowsWinRmHttps, WindowsDisableVMAgent, WindowsDisableVMAgentWinRmHttps
272302
Aliases:
273303
274304
Required: False
@@ -283,7 +313,7 @@ Indicates that this operating system uses HTTPS WinRM.
283313

284314
```yaml
285315
Type: SwitchParameter
286-
Parameter Sets: WindowsWinRmHttps
316+
Parameter Sets: WindowsWinRmHttps, WindowsDisableVMAgentWinRmHttps
287317
Aliases:
288318
289319
Required: True

0 commit comments

Comments
 (0)