The XA Reporting scripts

Posted: December 22, 2013 in Citrix
Tags: , , , , , , , , , ,

I’m still trying to figure out how to get the scripts loaded as attachments (sorry for the delay!)  But, I’m just going to post them as text.

# Name: New-DRFExternalAppAccess.ps1
#
# Author: David Figueroa
#
# Date: 11/21/2013
#
# Purpose: An automated script to enumerate the access to the external applications and produce a usable report describing this data.
#
# Credits:
# I wrote the XML document using this article = http://www.powershellmagazine.com/2013/08/19/mastering-everyday-xml-tasks-in-powershell/
#
# Import Citrix modules</div>
Add-PSSnapin -Name Citrix* -ErrorAction SilentlyContinue
Add-PSSnapin -Name ActiveDirectory -ErrorAction SilentlyContinue
#FUNCTIONS
# --------------------------------------------------------------------------------------------------------
# Create the XML file
# --------------------------------------------------------------------------------------------------------
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$FileSave = New-Object System.Windows.Forms.SaveFileDialog
$FileSave.AddExtension = $true
$FileSave.AutoUpgradeEnabled = $true
$FileSave.CheckPathExists = $true
$FileSave.CreatePrompt = $true
$FileSave.DefaultExt = 'xml'
$FileSave.Filter = 'XML Files (*.xml)|*.xml'
$FileSave.FilterIndex = 2
#$FileSave.InitialDirectory = [Environment]::GetFolderPath('MyDocuments')
$FileSave.OverwritePrompt = $true
$FileSave.ShowHelp = $false
$FileSave.SupportMultiDottedExtensions = $true
$FileSave.Title = 'Save the XML Application report...'
$FileSave.ValidateNames = $true
$FileSave.FileName = 'ServerFarm_Application_Report'
$FileSave.RestoreDirectory = $true
if ($FileSave.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
    $XMLPath = $FileSave.FileName
   } else {
     exit
   }
$XMLWriter = New-Object System.XML.XMLTextWriter($XMLPath, $Null)
#Set formatting
$XMLWriter.Formatting = 'Indented'
$XMLWriter.Indentation = 1
$XMLWriter.IndentChar = "`t"
#Write the header
$XMLWriter.WriteStartDocument()
#Set the XSL Statements
$XMLWriter.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='style.xsl'")
#--------------------------------------------------------------------------------------------------
# Enumerate Folders & Apps
#--------------------------------------------------------------------------------------------------
#Start with a Folders node
$XMLWriter.WriteStartElement('Folders') #Start Main 'Folders' Node
$BaseFolder = Get-XAFolder -FolderPath "Applications" -Recurse
$BaseFolder.FolderPath | foreach {
    $AppFolder = $_ 
    #Start a node for each folder
    #Create a "clean" name for the Node
    $AppFolderName = $AppFolder.Replace("/", "_")
    $XMLWriter.WriteStartElement('Folder') #Start individual Folder node
    $XMLWriter.WriteAttributeString("AppFolder",$AppFolder)
    #Enumerate the apps in that folder
    $Apps = Get-XAApplication -FolderPath $AppFolder
    $AppsCount = $Apps.Count
    $i = 1
    foreach ($App in $Apps) {
        Write-Progress -id 1 -Activity "Processing applications in $AppFolder" -Status "Progress: $i of $AppsCount" -PercentComplete ([int](($i/$Apps.Count)*100)) -CurrentOperation ($app.DisplayName)
    #Filter out spaces to write the XML node name
    $NodeName = $App.browsername.Replace(" ", "_")
    $XMLWriter.WriteStartElement('Applications') #Start the individual app node
    $XMLWriter.WriteAttributeString("AppName", $NodeName) 
    $XMLWriter.WriteAttributeString("BrowserName", $app.BrowserName) 
    $XMLWriter.WriteElementString('AccessSessionConditions', $app.AccessSessionConditions)
    $XMLWriter.WriteElementString('AccessSessionConditionsEnabled', $app.AccessSessionConditionsEnabled)
    $XMLWriter.WriteElementString('AddToClientDesktop', $app.AddToClientDesktop)
    $XMLWriter.WriteElementString('AddToClientStartMenu', $app.AddToClientStartMenu)
    $XMLWriter.WriteElementString('AlternateProfiles', $app.AlternateProfiles)
    $XMLWriter.WriteElementString('AnonymousConnectionsAllowed', $app.AnonymousConnectionsAllowed)
    $XMLWriter.WriteElementString('ApplicationId', $app.ApplicationId)
    $XMLWriter.WriteElementString('ApplicationType', $app.ApplicationType)
    $XMLWriter.WriteElementString('AudioRequired', $app.AudioRequired)
    $XMLWriter.WriteElementString('AudioType', $app.AudioType)
    $XMLWriter.WriteElementString('BrowserName', $app.BrowserName)
    $XMLWriter.WriteElementString('CachingOption', $app.CachingOption)
    $XMLWriter.WriteElementString('ClientFolder', $app.ClientFolder)
    $XMLWriter.WriteElementString('ColorDepth', $app.ColorDepth)
    $XMLWriter.WriteElementString('CommandLineExecutable', $app.CommandLineExecutable)
    $XMLWriter.WriteElementString('ConnectionsThroughAccessGatewayAllowed', $app.ConnectionsThroughAccessGatewayAllowed)
    $XMLWriter.WriteElementString('ContentAddress', $app.ContentAddress)
    $XMLWriter.WriteElementString('CpuPriorityLevel', $app.CpuPriorityLevel)
    $XMLWriter.WriteElementString('Description', $app.Description)
    $XMLWriter.WriteElementString('DisplayName', $app.DisplayName)
    $XMLWriter.WriteElementString('Enabled', $app.Enabled)
    $XMLWriter.WriteElementString('EncryptionLevel', $app.EncryptionLevel)
    $XMLWriter.WriteElementString('EncryptionRequired', $app.EncryptionRequired)
    $XMLWriter.WriteElementString('FolderPath', $app.FolderPath)
    $XMLWriter.WriteElementString('HideWhenDisabled', $app.HideWhenDisabled)
    $XMLWriter.WriteElementString('InstanceLimit', $app.InstanceLimit)
    $XMLWriter.WriteElementString('LoadBalancingApplicationCheckEnabled', $app.LoadBalancingApplicationCheckEnabled)
    $XMLWriter.WriteElementString('MachineName', $app.MachineName)
    $XMLWriter.WriteElementString('MaximizedOnStartup', $app.MaximizedOnStartup)
    $XMLWriter.WriteElementString('MultipleInstancesPerUserAllowed', $app.MultipleInstancesPerUserAllowed)
    $XMLWriter.WriteElementString('OfflineAccessAllowed', $app.OfflineAccessAllowed)
    $XMLWriter.WriteElementString('OtherConnectionsAllowed', $app.OtherConnectionsAllowed)
    $XMLWriter.WriteElementString('PreLaunch', $app.PreLaunch)
    $XMLWriter.WriteElementString('ProfileLocation', $app.ProfileLocation)
    $XMLWriter.WriteElementString('ProfileProgramArguments', $app.ProfileProgramArguments)
    $XMLWriter.WriteElementString('ProfileProgramName', $app.ProfileProgramName)
    $XMLWriter.WriteElementString('RunAsLeastPrivilegedUser', $app.RunAsLeastPrivilegedUser)
    $XMLWriter.WriteElementString('SequenceNumber', $app.SequenceNumber)
    $XMLWriter.WriteElementString('SslConnectionEnabled', $app.SslConnectionEnabled)
    $XMLWriter.WriteElementString('StartMenuFolder', $app.StartMenuFolder)
    $XMLWriter.WriteElementString('TitleBarHidden', $app.TitleBarHidden)
    $XMLWriter.WriteElementString('WaitOnPrinterCreation', $app.WaitOnPrinterCreation)
    $XMLWriter.WriteElementString('WindowType', $app.WindowType)
    $XMLWriter.WriteElementString('WorkingDirectory', $app.WorkingDirectory)
    #Now that we have the properties, get the application report properties, and store those
    $AppReportProperties = Get-XAApplicationReport -BrowserName $app.BrowserName
    #Now write the other elements that are relevant
    #ServerNames is a space delimited list, so break them out as individual elements
    foreach ($server in $AppReportProperties.ServerNames) {
        $XMLWriter.WriteElementString('Server', $server)
        }
    #Now get the accounts
    foreach ($account in $AppReportProperties.Accounts) {
        if ($account.AccountType -eq 'Group') {
            #Start a group node
            $XMLWriter.WriteStartElement('Group') #Start Group Element
            $XMLWriter.WriteAttributeString('GroupName', $account.AccountName)
            #Now get the group members and write those out, as a subnode
            $GroupMembers = Get-ADGroupMember -Identity ($account.AccountName)
            foreach ($member in $GroupMembers) {
                $XMLWriter.WriteElementString('GroupUser', $member.name)
            }
            $XMLWriter.WriteEndElement() #End the group node
            } else {
            $XMLWriter.WriteElementString('User', $account.AccountName)
            } #Close If ($account..)
         } #Close ForEach ($account...)
         $xmlWriter.WriteEndElement() #End the App Node 
         #Increment $i for the progress bar
         $i++
     } #Close the ForEach ($app...) 
     $XMLWriter.WriteEndElement() #Close Individual Folder Node?
 } #Close BaseFolder ForEach
 $XMLWriter.WriteEndElement()#Close the Main 'Folders' node
#Close up the XML
$XMLWriter.WriteEndDocument()
$XMLWriter.Flush()$XMLWriter.Close()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s