$keyVault = Get-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $rgName; $diskEncryptionKeyVaultUrl = $keyVault.VaultUri; $keyVaultResourceId = $keyVault.ResourceId; $keyEncryptionKeyUrl = (Get-AzKeyVaultKey -VaultName $keyVaultName -Name myKey).Key.kid;

Set-AzVMDiskEncryptionExtension -ResourceGroupName $rgName ` -VMName “myVM” `

-DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl `

-DiskEncryptionKeyVaultId $keyVaultResourceId `

-KeyEncryptionKeyUrl $keyEncryptionKeyUrl `

-KeyEncryptionKeyVaultId $keyVaultResourceId

 

For linux servers there might be an error as “Object reference not set to an instance of an object”.

To get around this issue, simply run the Set-AzVMDiskEncryptionExtension 
command with -SkipVmBackup option.