Skip to content

Commit 37694ee

Browse files
authored
Merge pull request Azure#3616 from SudhakaraReddyEvuri/dev
Script to clear encryption settings from VM model
2 parents 231fe3a + eb603ca commit 37694ee

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Param(
2+
[Parameter(Mandatory = $true,
3+
HelpMessage="Name of the resource group to which the VM belongs to")]
4+
[ValidateNotNullOrEmpty()]
5+
[string]$resourceGroupName,
6+
7+
[Parameter(Mandatory = $true,
8+
HelpMessage="Name of the VM")]
9+
[ValidateNotNullOrEmpty()]
10+
[string]$vmName
11+
)
12+
13+
$VerbosePreference = "Continue";
14+
$ErrorActionPreference = "Stop";
15+
16+
17+
Write-Verbose "ClearEncryptionSettings: resourceGroupName - $resourceGroupName , vmName - $vmName";
18+
19+
# Get the VM object
20+
$vm = Get-AzureRmVm -ResourceGroupName $resourceGroupName -Name $vmName;
21+
22+
Write-Verbose "VM object encryption settings before clearing encryption settings: $vm.StorageProfile.OsDisk.EncryptionSettings";
23+
24+
# Clear encryption settings and disable encryption on VM object
25+
$vm.StorageProfile.OsDisk.EncryptionSettings.Enabled = $false;
26+
$vm.StorageProfile.OsDisk.EncryptionSettings.DiskEncryptionKey = $null;
27+
$vm.StorageProfile.OsDisk.EncryptionSettings.KeyEncryptionKey = $null;
28+
29+
Write-Verbose "Cleared encryptionSettings: $vm.StorageProfile.OsDisk.EncryptionSettings";
30+
31+
#Stop VM, Update VM model to clear encryption settings and then start VM
32+
Stop-AzureRmVM -Name $vmName -ResourceGroupName $resourceGroupName -Force -Verbose;
33+
34+
Write-Verbose "Successfully stopped VM";
35+
36+
Update-AzureRmVM -VM $vm -ResourceGroupName $resourceGroupName -Verbose;
37+
38+
Write-Verbose "Successfully updated VM";
39+
40+
Start-AzureRmVm -ResourceGroupName $resourceGroupName -Name $vmName -Verbose;
41+
42+
Write-Verbose "Successfully started VM";
43+
44+
$vm = Get-AzureRmVm -ResourceGroupName $resourceGroupName -Name $vmName;
45+
46+
Write-Verbose "VM object encryption settings after clearing encryption settings: $vm.StorageProfile.OsDisk.EncryptionSettings";

0 commit comments

Comments
 (0)