Public/Get-CitrixXA7Applications.ps1
<#
.SYNOPSIS Retrieves Citrix XenApp 7 published applications and their associated delivery group and user mappings. .DESCRIPTION The Get-CitrixXA7Applications function queries a specified Citrix Delivery Controller for published applications, including their delivery groups, user access rules, and server counts. It supports filtering by application status (enabled/disabled) and exporting the results to a CSV file for reporting purposes. .PARAMETER AdminAddress The FQDN or name of the Citrix Delivery Controller to connect to for retrieving published application information. .PARAMETER ExportToCsv If specified as $true, the output will be saved to a timestamped CSV file in the C:\Temp folder. Default is $false. .PARAMETER ShowEnabledOnly Controls whether to return only enabled applications. Set to $false to retrieve disabled applications. Default is $true. .EXAMPLE # Retrieve only enabled applications (default behavior) Get-CitrixXA7Applications -AdminAddress "ddc001" .EXAMPLE # Retrieve disabled applications Get-CitrixXA7Applications -AdminAddress "ddc001" -ShowEnabledOnly $false .EXAMPLE # Export enabled applications to a CSV file Get-CitrixXA7Applications -AdminAddress "ddc001" -ExportToCsv $true .EXAMPLE # Export disabled applications to a CSV file Get-CitrixXA7Applications -AdminAddress "ddc001" -ExportToCsv $true -ShowEnabledOnly $false .NOTES This function is useful for auditing, capacity planning, and compliance validation in Citrix environments. #> function Get-CitrixXA7Applications { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$AdminAddress, [Parameter()] [bool]$ExportToCsv = $false, [Parameter()] [bool]$ShowEnabledOnly = $true ) process { # Get Delivery Groups $deliveryGroups = Get-BrokerDesktopGroup -SessionSupport MultiSession -AdminAddress $AdminAddress # Get all applications based on enabled filter $applications = Get-BrokerApplication -AdminAddress $AdminAddress | Where-Object { $_.Enabled -eq $ShowEnabledOnly } $result = foreach ($app in $applications) { $associatedDGs = $deliveryGroups | Where-Object { $app.AssociatedDesktopGroupUids -contains $_.Uid } foreach ($dg in $associatedDGs) { $associatedUsers = if (-not $app.AssociatedUserNames) { $accessRule = Get-BrokerAccessPolicyRule -DesktopGroupName $dg.Name -AllowedConnections ViaAG $accessRule.IncludedUsers.Name | Where-Object { $_ -ne "AMERICAS\CitrixApplicationAccess" } } else { $app.AssociatedUserNames | Where-Object { $_ -ne "AMERICAS\CitrixApplicationAccess" } } [PSCustomObject]@{ HostedOn = "XenApp 7" DeliveryGroup = $dg.Name ApplicationName = $app.ApplicationName Enabled = $app.Enabled GroupName = ($associatedUsers -join ', ') TotalServers = $dg.TotalDesktops } } } if ($ExportToCsv) { $outputPath = "C:\Temp\Citrix_XA7_Apps_$(if ($ShowEnabledOnly) {'Enabled'} else {'Disabled'})_$(Get-Date -Format 'yyyy-MM-dd_HH-mm-ss').csv" $result | Export-Csv -Path $outputPath -NoTypeInformation -Encoding UTF8 Write-LogEntry -Message "Application data exported to $outputPath" } else { return $result } } } |