Skip to content

Commit fd9a252

Browse files
authored
Merge pull request #5848 from SudhakaraReddyEvuri/suredd-ade-prereqfix
Update ADE Sample script to enable encryption on all the VMs in resource group, subscription
2 parents 56ada98 + 98ff49c commit fd9a252

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/Scripts/AzureDiskEncryptionPreRequisiteSetup.ps1

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ $ErrorActionPreference = "Stop"
4343
########################################################################################################################
4444
# Section1: Log-in to Azure and select appropriate subscription.
4545
########################################################################################################################
46-
4746

4847
Select-AzureRmSubscription -SubscriptionId $subscriptionId;
4948

50-
5149
########################################################################################################################
5250
# Section2: Create AAD app . Fill in $aadClientSecret variable if AAD app was already created
5351
########################################################################################################################
5452

55-
5653
# Check if AAD app with $aadAppName was already created
5754
$SvcPrincipals = (Get-AzureRmADServicePrincipal -SearchString $aadAppName);
5855
if(-not $SvcPrincipals)
@@ -187,7 +184,36 @@ $ErrorActionPreference = "Stop"
187184
Read-Host;
188185

189186
########################################################################################################################
190-
# For each VM you want to encrypt, run the below cmdlet
191-
# $vmName = 'Name of VM to encrypt';
192-
# Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $resourceGroupName -VMName $vmName -AadClientID $aadClientID -AadClientSecret $aadClientSecret -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId -VolumeType All
187+
# To encrypt one VM in given resource group of the logged in subscritpion, assign $vmName and uncomment below section
188+
########################################################################################################################
189+
#$vmName = "Your VM Name";
190+
#$allVMs = Get-AzureRmVm -ResourceGroupName $resourceGroupName -Name $vmName;
191+
192+
########################################################################################################################
193+
# To encrypt all the VMs in the given resource group of the logged in subscription uncomment below section
193194
########################################################################################################################
195+
#$allVMs = Get-AzureRmVm -ResourceGroupName $resourceGroupName;
196+
197+
########################################################################################################################
198+
# To encrypt all the VMs in the all the resource groups of the logged in subscription, uncomment below section
199+
########################################################################################################################
200+
#$allVMs = Get-AzureRmVm;
201+
202+
########################################################################################################################
203+
# Loop through the selected list of VMs and enable encryption
204+
########################################################################################################################
205+
206+
foreach($vm in $allVMs)
207+
{
208+
Write-Host "Encrypting VM: $($vm.Name) in ResourceGroup: $($vm.ResourceGroupName) " -foregroundcolor Green;
209+
if(-not $kek)
210+
{
211+
Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name -AadClientID $aadClientID -AadClientSecret $aadClientSecret -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId -VolumeType 'All';
212+
}
213+
else
214+
{
215+
Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name -AadClientID $aadClientID -AadClientSecret $aadClientSecret -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $keyVaultResourceId -KeyEncryptionKeyUrl $keyEncryptionKeyUrl -KeyEncryptionKeyVaultId $keyVaultResourceId -VolumeType 'All';
216+
}
217+
# Show encryption status of the VM
218+
Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name;
219+
}

0 commit comments

Comments
 (0)