Skip to content

Commit 9926ea5

Browse files
grizzlytheodoreTheodore ChangVeryEarly
authored
Reimage Support of standalone Non-Ephemeral VM (#21320)
* update * Update ChangeLog.md --------- Co-authored-by: Theodore Chang <[email protected]> Co-authored-by: Yabo Hu <[email protected]>
1 parent 3ba766b commit 9926ea5

File tree

3 files changed

+114
-5
lines changed

3 files changed

+114
-5
lines changed

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
2121
-->
2222
## Upcoming Release
23-
* Removed the image alias `CoreOS` as the publisher CoreOS no longer has any images for Azure.
24-
* Updated the names of the `openSUSE-Leap` and `SLES` aliases to `OpenSuseLeap154` and `SuseSles15SP4` respectively. Updated these aliases to point to an image that actually exists and updated the alias names to be descriptive and versioned.
25-
* Added new descriptive and versioned alias names for the Linux image aliases.
2623
* Addressed bug in `Remove-AzVmss` to throw error when `-InstanceId` is null. [#21162]
24+
* Added `-CustomData`, `-AdminPassword`, and `-ExactVersion` parameters to `Invoke-AzVMReimage`.
2725
* Removed the image alias `CoreOS` as the publisher CoreOS no longer has any images for Azure.
2826
Updated the names of the `openSUSE-Leap` and `SLES` aliases to `OpenSuseLeap154` and `SuseSles15SP4` respectively. Updated these aliases to point to an image that actually exists.
2927
* Added a breaking change warning to `New-AzVM` and `New-AzVmss` for future planned image alias removals due to the images reaching their End of Support date.

src/Compute/Compute/Generated/VirtualMachine/VirtualMachineReimageMethod.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,34 @@ public override void ExecuteCmdlet()
4343
{
4444
if (ShouldProcess(this.VMName, VerbsLifecycle.Invoke))
4545
{
46+
VirtualMachineReimageParameters vmReimageParams = new VirtualMachineReimageParameters();
47+
vmReimageParams.TempDisk = this.TempDisk.IsPresent ? true : (bool?)null;
4648
string resourceGroupName = this.ResourceGroupName;
4749
string vmName = this.VMName;
48-
bool? tempDisk = this.TempDisk.IsPresent ? true : (bool?)null;
4950

50-
var result = VirtualMachinesClient.ReimageWithHttpMessagesAsync(resourceGroupName, vmName, tempDisk).GetAwaiter().GetResult();
51+
if (this.IsParameterBound(c => c.ExactVersion))
52+
{
53+
vmReimageParams.ExactVersion = this.ExactVersion;
54+
}
55+
56+
if (this.IsParameterBound(c => c.CustomData))
57+
{
58+
if (vmReimageParams.OsProfile == null) {
59+
vmReimageParams.OsProfile = new OSProfileProvisioningData();
60+
}
61+
vmReimageParams.OsProfile.CustomData = this.CustomData;
62+
}
63+
64+
if (this.IsParameterBound(c => c.AdminPassword))
65+
{
66+
if (vmReimageParams.OsProfile == null)
67+
{
68+
vmReimageParams.OsProfile = new OSProfileProvisioningData();
69+
}
70+
vmReimageParams.OsProfile.AdminPassword = this.AdminPassword;
71+
}
72+
73+
var result = VirtualMachinesClient.ReimageWithHttpMessagesAsync(resourceGroupName, vmName, vmReimageParams).GetAwaiter().GetResult();
5174
PSOperationStatusResponse output = new PSOperationStatusResponse
5275
{
5376
StartTime = this.StartTime,
@@ -87,5 +110,23 @@ public override void ExecuteCmdlet()
87110

88111
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
89112
public SwitchParameter AsJob { get; set; }
113+
114+
[Parameter(
115+
Mandatory = false,
116+
ValueFromPipelineByPropertyName = true,
117+
HelpMessage = "Specifies in decimal number, the version the OS disk should be reimaged to. If exact version is not provided, the OS disk is reimaged to the existing version of OS Disk.")]
118+
public string ExactVersion { get; set; }
119+
120+
[Parameter(
121+
Mandatory = false,
122+
ValueFromPipelineByPropertyName = true,
123+
HelpMessage = "Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes.")]
124+
public string CustomData { get; set; }
125+
126+
[Parameter(
127+
Mandatory = false,
128+
ValueFromPipelineByPropertyName = true,
129+
HelpMessage = "Specifies the password of the administrator account.")]
130+
public string AdminPassword { get; set; }
90131
}
91132
}

src/Compute/Compute/help/Invoke-AzVMReimage.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Reimage an Azure virtual machine.
1414

1515
```
1616
Invoke-AzVMReimage [-ResourceGroupName] <String> [-VMName] <String> [-TempDisk] [-AsJob]
17+
[-ExactVersion <String>] [-CustomData <String>] [-AdminPassword <String>]
1718
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1819
```
1920

@@ -29,8 +30,43 @@ Invoke-AzVMReimage -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
2930

3031
This command reimages the virtual machine named VirtualMachine07 in ResourceGroup11.
3132

33+
### Example 2
34+
```powershell
35+
$SecurePassword = ConvertTo-SecureString "password" -AsPlainText
36+
Invoke-AzVMReimage -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -TempDisk -CustomData $CustomData -AdminPassword $SecurePassword -ExactVersion "10.0.14393.0"
37+
```
38+
39+
Passing in -AdminPassword using SecureString along with other parameters to reimage the virtual machine.
40+
3241
## PARAMETERS
3342

43+
### -AdminPassword
44+
Specifies the password of the administrator account.
45+
<br><br> **Minimum-length (Windows):** 8 characters
46+
<br><br> **Minimum-length (Linux):** 6 characters
47+
<br><br> **Max-length (Windows):** 123 characters
48+
<br><br> **Max-length (Linux):** 72 characters
49+
<br><br> **Complexity requirements:** 3 out of 4 conditions below need to be fulfilled
50+
<br> Has lower characters
51+
<br>Has upper characters
52+
<br> Has a digit
53+
<br> Has a special character (Regex match [\\W_])
54+
<br><br> **Disallowed values:** \"abc@123\", \"P@$$w0rd\", \"P@ssw0rd\", \"P@ssword123\", \"Pa$$word\", \"pass@word1\", \"Password!\", \"Password1\", \"Password22\", \"iloveyou!\"
55+
<br><br> For resetting the password, see [How to reset the Remote Desktop service or its login password in a Windows VM](https://docs.microsoft.com/troubleshoot/azure/virtual-machines/reset-rdp)
56+
<br><br> For resetting root password, see [Manage users, SSH, and check or repair disks on Azure Linux VMs using the VMAccess Extension](https://docs.microsoft.com/troubleshoot/azure/virtual-machines/troubleshoot-ssh-connection)
57+
58+
```yaml
59+
Type: System.String
60+
Parameter Sets: (All)
61+
Aliases:
62+
63+
Required: False
64+
Position: Named
65+
Default value: None
66+
Accept pipeline input: True (ByPropertyName)
67+
Accept wildcard characters: False
68+
```
69+
3470
### -AsJob
3571
Run cmdlet in the background
3672
@@ -46,6 +82,25 @@ Accept pipeline input: False
4682
Accept wildcard characters: False
4783
```
4884
85+
### -CustomData
86+
Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes.
87+
<br><br> **Note: Do not pass any secrets or passwords in customData property**
88+
<br><br> This property cannot be updated after the VM is created.
89+
<br><br> customData is passed to the VM to be saved as a file, for more information see [Custom Data on Azure VMs](https://azure.microsoft.com/blog/custom-data-and-cloud-init-on-windows-azure/)
90+
<br><br> For using cloud-init for your Linux VM, see [Using cloud-init to customize a Linux VM during creation](https://docs.microsoft.com/azure/virtual-machines/linux/using-cloud-init)
91+
92+
```yaml
93+
Type: System.String
94+
Parameter Sets: (All)
95+
Aliases:
96+
97+
Required: False
98+
Position: Named
99+
Default value: None
100+
Accept pipeline input: True (ByPropertyName)
101+
Accept wildcard characters: False
102+
```
103+
49104
### -DefaultProfile
50105
The credentials, account, tenant, and subscription used for communication with Azure.
51106
@@ -61,6 +116,21 @@ Accept pipeline input: False
61116
Accept wildcard characters: False
62117
```
63118
119+
### -ExactVersion
120+
Specifies in decimal number, the version the OS disk should be reimaged to. If exact version is not provided, the OS disk is reimaged to the existing version of OS Disk.
121+
122+
```yaml
123+
Type: System.String
124+
Parameter Sets: (All)
125+
Aliases:
126+
127+
Required: False
128+
Position: Named
129+
Default value: None
130+
Accept pipeline input: True (ByPropertyName)
131+
Accept wildcard characters: False
132+
```
133+
64134
### -ResourceGroupName
65135
Specifies the name of the resource group of the virtual machine.
66136

0 commit comments

Comments
 (0)