-
Notifications
You must be signed in to change notification settings - Fork 2
/
__AVDAlerts-MapVMHostPools.txt
73 lines (54 loc) · 3.72 KB
/
__AVDAlerts-MapVMHostPools.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$AVDResourceIDs = "[/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eus2-AutoDeployTest,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eus2-personal,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-AVDLab,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eastus2-GenUser-AADJoin,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eastus2-GraphicsIntensive,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eastus2-HybridJoinVMs,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eastus2-personal,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-eastus2-RemoteApps,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/p-eastus2-SSO,/subscriptions/8a0ecebc-0e1d-4e8f-8cb8-8a92f49455b9/resourceGroups/rg-eastus2-AVDLab-Resources/providers/Microsoft.DesktopVirtualization/hostpools/hp-xcloud-va-USGov]"
$ErrorActionPreference = 'Stop'
# Object for collecting output
$DeploymentScriptOutputs = @{}
Class HPInfo{
[string]$HostPoolName
[string]$HostPoolResId
[array] $VMNames
[array] $VMResourceIDs
}
$AllHPInfo = @()
# =================================================================================================
# AVD Host Pool RG Names
# =================================================================================================
Foreach ($itemID in $AVDResourceIDs) {
$AVDResourceRG = ($itemID -split '/')[4]
$SubID = ($itemID -split '/')[2]
$HostPools = Get-AzWvdHostPool -ResourceGroupName $AVDResourceRG -SubscriptionId $SubID
Foreach ($HostPool in $HostPools) {
$currHostPool = New-Object HPInfo
$VMResourceIDs = @()
$VMResourceRGIDs = @()
$VMNames = @()
$SessionHosts = (Get-AzWvdSessionHost -SubscriptionId $SubID -ResourceGroupName $AVDResourceRG -HostPoolName $HostPool.Name).Name
$HostPoolName = $HostPool.Name
$currHPInfo = @()
foreach($sessionHost in $SessionHosts){
$VMCurr = ($sessionHost -split '/')[1]
If ($sessionHost -ne "") {
$DotLocation = $VMCurr.IndexOf('.')
If ($DotLocation -ne -1) { $VM = $VMCurr.Substring(0, $DotLocation)}
$VMResID = (Get-AzVM -Name $VM).Id
If($VMResID.Count -gt 0){
$VMNamePart = ($VMResID -split '/')[8]
$VMNames += $VMNamePart
$VMResourceIDs += $VMResID
}
}
}
$HostPoolNames += $HostPoolName
$HostPoolResIds += $HostPoolResIds
$HostPoolVMNames += [array]$VMNames
$HostPoolVMResIDs += [array]$VMResourceIDs
$currHostPool.HostPoolName = $HostPoolName
$currHostPool.HostPoolResId = $HostPoolResID
$currHostPool.VMNames = $VMNames
$currHostPool.VMResourceIDs = $VMResourceIDs
$AllHPinfo += $currHostPool
}
}
# Convert to JSON
$AllHPInfoJson = $AllHPinfo | Convertto-Json
# Convert to String
$AllHPInfoSring = $AllHPInfo.ToString()