Public/Get-CitrixVDIDesktopGroups.ps1
<#
.SYNOPSIS Retrieves information about Citrix VDI (Single-session) Desktop Groups from a specified Delivery Controller. .DESCRIPTION The Get-CitrixVDIDesktopGroups function connects to a specified Citrix Delivery Controller and retrieves all desktop groups configured for single-session (VDI) use. It gathers details such as desktop group name, enabled state, total desktops, access policy users, and kind of desktop. The function optionally supports exporting the data to a CSV file. .PARAMETER ComputerName Specifies the FQDN or name of the Citrix Delivery Controller to query for VDI desktop group information. .PARAMETER ExportToCsv If specified as $true, the retrieved VDI desktop group information will be exported to a CSV file located in `C:\temp`. .EXAMPLE # Get all VDI desktop groups from the specified Delivery Controller Get-CitrixVDIDesktopGroups -ComputerName "ddc001" .EXAMPLE # Export the VDI desktop group information to CSV Get-CitrixVDIDesktopGroups -ComputerName "ddc001" -ExportToCsv $true .NOTES Use this function to gather details on Citrix VDI configurations for inventory, auditing, and reporting purposes. #> function Get-CitrixVDIDesktopGroups { [CmdletBinding()] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [string]$ComputerName, [Parameter(Mandatory = $false)] [bool]$ExportToCsv = $false ) process { try { $DeliveryGroups = Get-BrokerDesktopGroup -SessionSupport SingleSession -AdminAddress $ComputerName $Desktops = foreach ($DG in $DeliveryGroups) { $AccessPolicyRules = Get-BrokerAccessPolicyRule -DesktopGroupName $DG.Name -AllowedConnections ViaAG $FilteredUsers = if ($AccessPolicyRules) { ($AccessPolicyRules.IncludedUsers.Name | Where-Object { $_ -notmatch 'AMERICAS\\CitrixApplicationAccess' }) -join ', ' } else { "No access policy found" } [PSCustomObject]@{ HostedOn = "VDI" DeliveryGroup = $DG.Name DesktopName = $DG.Name Enabled = $DG.Enabled GroupName = $FilteredUsers TotalDesktops = $DG.TotalDesktops DesktopKind = $DG.DesktopKind } } if ($ExportToCsv) { $path = "C:\temp\CitrixVDIDesktops_$(Get-Date -Format 'MM-dd-yyyy').csv" $Desktops | Export-Csv -Path $path -NoTypeInformation -Append Write-LogEntry -Message "Data exported to $path" } else { $Desktops } } catch { Write-LogEntry -Message "Failed to retrieve desktop access info: $_" } } } |