Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save littletoyrobots/128b7d5068abcdd2d9ea36418007652a to your computer and use it in GitHub Desktop.

Select an option

Save littletoyrobots/128b7d5068abcdd2d9ea36418007652a to your computer and use it in GitHub Desktop.
#Requires -Module PSWriteHtml
#Requires -PSSnapin Citrix.Broker.Admin.V2
# Author: Adam Yarborough, 2020.
# Usage: .\Create-CitrixApplicationReference.ps1 -AdminAddress 'ddc1.domain.com' -Outfile 'C:\Reports\Whatever.html'
[cmdletbinding()]
param (
[string]$AdminAddress = $env:COMPUTERNAME,
[switch]$IgnoreApplicationsWithNoUsers,
[string]$Title = 'Application Mappings',
[int]$FontSize = 13,
[string]$OutFile = "$env:TEMP\ApplicationMappings-$(Get-Date -format filedate).html",
[string[]]$IgnoreAssociatedUsernames = @('ECLPTSC\ECL - SCM XA Support', 'ECLPTSC\TSS - Client Delivery', 'ECLPTSC\TSC - Application Integration')
)
# Recurse through each Admin Folder, displaying its own contents before
# each further nested folder.
function Get-NestedAdminFolderTable {
[cmdletbinding()]
param (
[string]$AdminAddress,
[Citrix.Broker.Admin.SDK.AdminFolder]$AdminFolder,
[int]$FontSize,
[string[]]$IgnoreAssociatedUsernames,
[switch]$IgnoreApplicationsWithNoUsers,
[switch]$IgnoreApplicationsWithNoMachines
)
process {
Write-Verbose "Table: $($AdminFolder.Name)"
# Each application in an Admin Folder will be an entry in the table.
$Applications = Get-BrokerApplication -AdminAddress $AdminAddress -AdminFolderUid $AdminFolder.Uid
$TableData = $Applications | ForEach-Object {
$AssociatedUsernames = $_.AssociatedUsernames
$AssociatedUsernames += $_.AssociatedApplicationGroupUids | ForEach-Object {
Get-BrokerApplicationGroup -AdminAddress $AdminAddress -Uid $_ | Select-Object -ExpandProperty AssociatedUsernames
}
# Bail often, bail early.
if (($AssociatedUsernames.Count -eq 0) -and $IgnoreApplicationsWithNoUsers) {
continue
}
$DesktopGroups = $_.AssociatedDesktopGroupUids | ForEach-Object {
Get-BrokerDesktopGroup -AdminAddress $AdminAddress -Uid $_ | Select-Object -ExpandProperty Name
}
$ApplicationGroups = $_.AssociatedApplicationGroupUids | ForEach-Object {
Get-BrokerApplicationGroup -AdminAddress $AdminAddress -Uid $_ | Select-Object -ExpandProperty Name
}
# Save only the data we care about, do formatting for the arrays
[PSCustomObject]@{
ApplicationName = $_.ApplicationName
Enabled = $_.Enabled
DesktopGroups = ($DesktopGroups | Sort-Object -Unique ) -join ' <br> '
ApplicationGroups = ($ApplicationGroups | Sort-Object -Unique ) -join ' <br> '
AssociatedUsernames = ($AssociatedUsernames | Sort-Object -Unique | Where-Object { $_ -NotIn $IgnoreAssociatedUsernames } ) -join ' <br> '
}
}
# Now with our populated table
New-HTMLSection -HeaderText $AdminFolder.Name -HeaderTextColor Black -HeaderBackGroundColor LightGreen -Collapsable {
New-HTMLTable -HideFooter -DataTable $TableData -InvokeHTMLTags {
New-HTMLTableContent -Names 'ApplicationName' -FontSize $FontSize -Alignment left
New-HTMLTableContent -Names 'Enabled' -FontSize $FontSize -Alignment left
New-HTMLTableContent -Names 'DesktopGroups' -FontSize $FontSize -Alignment left
New-HTMLTableContent -Names 'ApplicationGroups' -FontSize $FontSize -Alignment left
New-HTMLTableContent -Names 'AssociatedUserNames' -FontSize $FontSize -Alignment left
}
}
$NestedAdminFolders = Get-BrokerAdminFolder -AdminAddress $AdminAddress -ParentAdminFolderUid $AdminFolder.Uid
$NestedAdminFolders | ForEach-Object {
$NestedParams = @{
AdminAddress = $AdminAddress
AdminFolder = $_
FontSize = $FontSize
IgnoreAssociatedUsernames = $IgnoreAssociatedUsernames
IgnoreApplicationsWithNoUsers = $IgnoreApplicationsWithNoUsers
IgnoreApplicationsWithNoMachines = $IgnoreApplicationsWithNoMachines
}
#New-HTMLTab -Name $_.FolderName -HtmlData {
Get-NestedAdminFolderTable @NestedParams
#}
}
}
}
# Create new HTML document
New-HTML -Name $Title -FilePath $OutFile -UseJavaScriptLinks -UseCssLinks -HtmlData {
# For each top level Application Folder (no parent folder), make a tab
# and then present all further nested application folders as tables inside
# that tab. Top level 'Applications/' is implied
$AdminFolders = Get-BrokerAdminFolder -AdminAddress $AdminAddress -ParentAdminFolderUid 0
$AdminFolders | Where-Object { '' -ne $_.Name } | ForEach-Object {
Write-Verbose "Application Folder: $($_.Name)"
New-HTMLTab -Name $_.Name -HtmlData {
$Params = @{
AdminAddress = $AdminAddress
AdminFolder = $_
FontSize = $FontSize
IgnoreAssociatedUsernames = $IgnoreAssociatedUsernames
IgnoreApplicationsWithNoUsers = $IgnoreApplicationsWithNoUsers
IgnoreApplicationsWithNoMachines = $IgnoreApplicationsWithNoMachines
}
Get-NestedAdminFolderTable @Params
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment