Get All Groups and Users in AVD Assignments

This script will get all the user accounts and groups in your Azure Virtual Desktop Application Groups Assignments. It will output to a table with ApplicationGroupName, HostPoolName, SessionType, Assigned

            
Set-AzContext -Subscription 'Your Subscription'
            $azSubscription = (Get-AzContext).Subscription.Id
                        
            # Retrieve all Application Group information
            $wvdApplicationGroups = (Get-AzWvdApplicationGroup -SubscriptionId $azSubscription)

            # Initialize arrays to hold the output for personal and pooled host pools
            $personalResults = @()
            $pooledResults = @()

            # Loop through each application group
            foreach ($wvdApplicationGroup in $wvdApplicationGroups) {
                # Get the host pool associated with this application group
                $hostPool = Get-AzWvdHostPool -ResourceGroupName $($wvdApplicationGroup.Id.Split("/")[4]) -Name $($wvdApplicationGroup.HostPoolArmPath.Split("/")[8])
                
                # Retrieve the Assigned Users to this Application Group.
                $wvdAGUsers = Get-AzRoleAssignment -ResourceGroupName $($wvdApplicationGroup.Id.Split("/")[4]) -ResourceName $($wvdApplicationGroup.Name) -ResourceType "Microsoft.DesktopVirtualization/applicationGroups" -RoleDefinitionName "Desktop Virtualization User"
                
                # Loop through each assigned user
                foreach ($user in $wvdAGUsers) {
                    # Create a result object
                    $result = New-Object PSObject -Property @{
                        HostPoolName = $hostPool.Name
                        ApplicationGroupName = $wvdApplicationGroup.Name
                        AssignedUserName = $user.DisplayName
                    }

                    # Add the result to the corresponding array based on the host pool type
                    if ($hostPool.HostPoolType -eq 'Personal') {
                        $result | Add-Member -MemberType NoteProperty -Name "SessionType" -Value "Personal"
                        $personalResults += $result
                    } else {
                        $result | Add-Member -MemberType NoteProperty -Name "SessionType" -Value "Multisession"
                        $pooledResults += $result
                    }
                }
            }          
            # Display the results
            Write-Output "Personal Host Pool Assignments:"
            $personalResults | Format-Table -Property ApplicationGroupName, HostPoolName, SessionType, AssignedUserName -AutoSize
            Write-Output "Pooled Host Pool Assignments:"
            $pooledResults | Format-Table -Property ApplicationGroupName, HostPoolName, SessionType, AssignedUserName -AutoSize

         
 
Share or Save this:
Share