Skip to content

Commit 9ddd575

Browse files
Upload scripts to find ADE version (#13329)
1 parent 2f1af10 commit 9ddd575

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<#
2+
READ ME:
3+
This script finds Windows and Linux Virtual Machines encrypted with single pass ADE in all resource groups present in a subscription.
4+
INPUT:
5+
Enter the subscription ID of the subscription. DO NOT remove hyphens. Example: 759532d8-9991-4d04-878f-xxxxxxxxxxxx
6+
OUTPUT:
7+
A .csv file with file name "<SubscriptionId>_AdeVMInfo.csv" is created in the same working directory.
8+
Note: If the ADE_Version field = "Not Available" in the output, it means that the VM is encrypted but the extension version couldn't be found. Please check the version manually for these VMs.
9+
#>
10+
11+
$ErrorActionPreference = "Continue"
12+
$SubscriptionId = Read-Host("Enter Subscription ID")
13+
$setSubscriptionContext = Set-AzContext -SubscriptionId $SubscriptionId
14+
15+
if($setSubscriptionContext -ne $null)
16+
{
17+
$getAllVMInSubscription = Get-AzVM
18+
$outputContent = @()
19+
20+
foreach ($vmobject in $getAllVMInSubscription)
21+
{
22+
$vm_OS = ""
23+
if ($vmobject.OSProfile.WindowsConfiguration -eq $null)
24+
{
25+
$vm_OS = "Linux"
26+
}
27+
else
28+
{
29+
$vm_OS = "Windows"
30+
}
31+
32+
$vmInstanceView = Get-AzVM -ResourceGroupName $vmobject.ResourceGroupName -Name $vmobject.Name -Status
33+
34+
$isVMADEEncrypted = $false
35+
$isStoppedVM = $false
36+
$adeVersion = ""
37+
38+
#Find ADE extension version if ADE extension is installed
39+
$vmExtensions = $vmInstanceView.Extensions
40+
foreach ($extension in $vmExtensions)
41+
{
42+
if ($extension.Name -like "azurediskencryption*")
43+
{
44+
$adeVersion = $extension.TypeHandlerVersion
45+
$isVMADEEncrypted = $true
46+
break;
47+
}
48+
}
49+
50+
#Look for encryption settings on disks. This applies to VMs that are in deallocated state
51+
#Extension version information is unavailable for stopped VMs
52+
if ($isVMADEEncrypted -eq $false)
53+
{
54+
$disks = $vmInstanceView.Disks
55+
foreach ($diskObject in $disks)
56+
{
57+
if ($diskObject.EncryptionSettings -ne $null)
58+
{
59+
$isStoppedEncryptedVM = $true
60+
break;
61+
}
62+
}
63+
}
64+
65+
if ($isVMADEEncrypted)
66+
{
67+
#Prepare output content for single pass VMs
68+
if ((($vm_OS -eq "Windows") -and ($adeVersion -like "2.*")) -or (($vm_OS -eq "Linux") -and ($adeVersion -like "1.*")))
69+
{
70+
$results = @{
71+
VMName = $vmobject.Name
72+
ResourceGroupName = $vmobject.ResourceGroupName
73+
VM_OS = $vm_OS
74+
ADE_Version = $adeVersion
75+
}
76+
$outputContent += New-Object PSObject -Property $results
77+
Write-Host "Added details for encrypted VM " $vmobject.Name
78+
}
79+
}
80+
elseif ($isStoppedEncryptedVM)
81+
{
82+
$results = @{
83+
VMName = $vmobject.Name
84+
ResourceGroupName = $vmobject.ResourceGroupName
85+
VM_OS = $vm_OS
86+
ADE_Version = "Not Available"
87+
}
88+
$outputContent += New-Object PSObject -Property $results
89+
Write-Host "Added details for encrypted VM. ADE version = Not available " $vmobject.Name
90+
}
91+
}
92+
93+
#Write to output file
94+
$filePath = ".\" + $SubscriptionId + "_AdeVMInfo.csv"
95+
$outputContent | export-csv -Path $filePath -NoTypeInformation
96+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<#
2+
READ ME:
3+
This script finds Windows and Linux Virtual Machine Scale Sets encrypted with single pass ADE in all resource groups present in a subscription.
4+
INPUT:
5+
Enter the subscription ID of the subscription. DO NOT remove hyphens. Example: 759532d8-9991-4d04-878f-xxxxxxxxxxxx
6+
OUTPUT:
7+
A .csv file with file name "<SubscriptionId>__AdeVMSSInfo.csv" is created in the same working directory.
8+
Note: If the ADE_Version field = "Not Available" in the output, it means that the VM is encrypted but the extension version couldn't be found. Please check the version manually for these VMSS.
9+
#>
10+
11+
$ErrorActionPreference = "Continue"
12+
$SubscriptionId = Read-Host("Enter Subscription ID")
13+
$setSubscriptionContext = Set-AzContext -SubscriptionId $SubscriptionId
14+
15+
if($setSubscriptionContext -ne $null)
16+
{
17+
$getAllVMSSInSubscription = Get-AzVmss
18+
$outputContent = @()
19+
20+
foreach ($vmssobject in $getAllVMSSInSubscription)
21+
{
22+
$vmssModel = Get-AzVmss -ResourceGroupName $vmssobject.ResourceGroupName -VMScaleSetName $vmssobject.Name
23+
if ($vmssModel.VirtualMachineProfile.OsProfile.WindowsConfiguration -eq $null)
24+
{
25+
$vmss_OS = "Linux"
26+
}
27+
else
28+
{
29+
$vmss_OS = "Windows"
30+
}
31+
32+
$isVMSSADEEncrypted = $false
33+
$adeVersion = ""
34+
35+
#find if VMSS has ADE extension installed
36+
$vmssExtensions = $vmssObject.VirtualMachineProfile.ExtensionProfile.Extensions
37+
foreach ($extension in $vmssExtensions)
38+
{
39+
if ($extension.Type -like "azurediskencryption*")
40+
{
41+
$isVMSSADEEncrypted = $true
42+
break;
43+
}
44+
}
45+
46+
#find ADE extension version if VMSS has ADE installed.
47+
if ($isVMSSADEEncrypted)
48+
{
49+
$vmssInstanceView = Get-AzVmssVM -ResourceGroupName $vmssobject.ResourceGroupName -VMScaleSetName $vmssobject.Name -InstanceView
50+
$vmssInstanceId = $vmssInstanceView[0].InstanceId
51+
$vmssVMInstanceView = Get-AzVmssVM -ResourceGroupName $vmssobject.ResourceGroupName -VMScaleSetName $vmssobject.Name -InstanceView -InstanceId $vmssInstanceId
52+
53+
$vmssExtensions = $vmssVMInstanceView.Extensions
54+
foreach ($extension in $vmssExtensions)
55+
{
56+
if ($extension.Type -like "Microsoft.Azure.Security.Azurediskencryption*")
57+
{
58+
$adeVersion = $extension.TypeHandlerVersion
59+
break;
60+
}
61+
}
62+
63+
#Prepare output content for single pass VMSS
64+
if ((($vmss_OS -eq "Windows") -and ($adeVersion -like "2.*")) -or (($vmss_OS -eq "Linux") -and ($adeVersion -like "1.*")))
65+
{
66+
$results = @{
67+
VMSSName = $vmssobject.Name
68+
ResourceGroupName = $vmssobject.ResourceGroupName
69+
VMSS_OS = $vmss_OS
70+
ADE_Version = $adeVersion
71+
}
72+
$outputContent += New-Object PSObject -Property $results
73+
Write-Host "Added details for encrypted VMSS" $vmssobject.Name
74+
}
75+
elseif ([string]::IsNullOrEmpty($adeVersion))
76+
{
77+
$results = @{
78+
VMSSName = $vmssobject.Name
79+
ResourceGroupName = $vmssobject.ResourceGroupName
80+
VMSS_OS = $vmss_OS
81+
ADE_Version = "Not Available"
82+
}
83+
$outputContent += New-Object PSObject -Property $results
84+
Write-Host "Added details for encrypted VMSS. ADE version = Not available" $vmssobject.Name
85+
}
86+
}
87+
}
88+
89+
#Write to output file
90+
$filePath = ".\" + $SubscriptionId + "_AdeVMSSInfo.csv"
91+
$outputContent | export-csv -Path $filePath -NoTypeInformation
92+
}

0 commit comments

Comments
 (0)