@@ -14,33 +14,30 @@ $VerbosePreference = "Continue";
14
14
$ErrorActionPreference = " Stop" ;
15
15
16
16
17
- Write-Verbose " ClearEncryptionSettings: resourceGroupName - $resourceGroupName , vmName - $vmName " ;
17
+ # Stop VM, Update VM model to clear encryption settings and then start VM
18
+ Write-Verbose " Stopping VM resourceGroupName - $resourceGroupName , vmName - $vmName " ;
19
+ Stop-AzureRmVM - Name $vmName - ResourceGroupName $resourceGroupName - Force - Verbose;
20
+ Write-Verbose " Successfully stopped VM" ;
18
21
19
22
# Get the VM object
20
23
$vm = Get-AzureRmVm - ResourceGroupName $resourceGroupName - Name $vmName ;
21
-
22
- Write-Verbose " VM object encryption settings before clearing encryption settings: $vm .StorageProfile.OsDisk.EncryptionSettings" ;
24
+ $backupEncryptionSettings = $vm.StorageProfile.OsDisk.EncryptionSettings ;
23
25
24
26
# Clear encryption settings and disable encryption on VM object
27
+ Write-Verbose " ClearEncryptionSettings: resourceGroupName - $resourceGroupName , vmName - $vmName " ;
28
+ Write-Verbose " VM object encryption settings before clearing encryption settings: $vm .StorageProfile.OsDisk.EncryptionSettings" ;
25
29
$vm.StorageProfile.OsDisk.EncryptionSettings.Enabled = $false ;
26
30
$vm.StorageProfile.OsDisk.EncryptionSettings.DiskEncryptionKey = $null ;
27
31
$vm.StorageProfile.OsDisk.EncryptionSettings.KeyEncryptionKey = $null ;
28
-
29
32
Write-Verbose " Cleared encryptionSettings: $vm .StorageProfile.OsDisk.EncryptionSettings" ;
30
33
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
-
34
+ # Update VM with cleared encryption settings
36
35
Update-AzureRmVM - VM $vm - ResourceGroupName $resourceGroupName - Verbose;
37
-
38
36
Write-Verbose " Successfully updated VM" ;
39
37
38
+ # Start the VM
40
39
Start-AzureRmVm - ResourceGroupName $resourceGroupName - Name $vmName - Verbose;
41
-
42
40
Write-Verbose " Successfully started VM" ;
43
41
44
42
$vm = Get-AzureRmVm - ResourceGroupName $resourceGroupName - Name $vmName ;
45
-
46
43
Write-Verbose " VM object encryption settings after clearing encryption settings: $vm .StorageProfile.OsDisk.EncryptionSettings" ;
0 commit comments