Posts RSS Comments RSS 253 Posts and 411 Comments till now

Blog Archives

Get-CitrixSessionUser.ps1 (Citrix Top 10)

One of the script I was asked to convert was a script to output all the Users and the Client IP.

This is what I came up with

Name: Get-CitrixSessionUser.ps1
Purpose: List ClientAddress and UserName for each Session

# Get-CitrixSessionUser.ps1
# Brandon Shell [MVP]
# www.bsonposh.com
# List ClientAddress and UserName for each Session

$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.Sessions | Format-Table UserName,ClientAddress

After I did this… I stopped and actually thought about what I was doing. What is the point? What would someone use this for? It seemed to me that a simpler script that was more flexible would not only meet the original goal, but expand it significantly. It comes back to the object nature of Powershell. I needed to stop thinking strings and start thinking objects. Using the following script not only accomplishes the same goal to get UserName and ClientAddress, but also expands it to add the following:

AAName
AAType
AccessSessionGuid
Applications
AppliedPolicy
AppName
AverageLatency
BandwidthCap
BytesRcvdPostExpansion
BytesRcvdPreExpansion
BytesSentPostCompression
BytesSentPreCompression
ClientAddress
ClientAddrFamily
ClientBuffers
ClientBuild
ClientCacheDisk
ClientCacheLowMem
ClientCacheTiny
ClientCacheXms
ClientColorDepth
ClientDimBitmapMin
ClientDimCacheSize
ClientDimVersion
ClientDirectory
ClientEncryption
ClientHardwareID
ClientHRes
ClientID
ClientLicense
ClientModemName
ClientModules
ClientName
ClientProductID
ClientProductIDValue
ClientVRes
DeviceID
ICABufLen
InputSpeed
LastLatency
LatencyDeviation
OutputSpeed
Processes
ProtocolType
ServerBuffers
ServerName
SessionID
SessionName
SessionState
SmartAccessFilters
UserName
VIPAddress
VirtualChannels

# Get-CitrixSession.ps1
# Brandon Shell [MVP]
# www.bsonposh.com
# Gets all the Sessions for a Farm

$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.Sessions

How to Manage Multiple Citrix Farms

Chris left a comment on Powershelling Citrix (The Good, Bad, and The Code)

Here is a function that returns a farm object for Server that is passed.

function Get-CitrixFarm {
   Param([string]$server)
   $type = [system.Type]::GetTypeFromProgID("MetaframeCOM.MetaFrameFarm",$server)
   $farm = [system.Activator]::CreateInstance($type)
   $farm.Initialize(1)
   return $farm
}
 

Here is an example to find a Server that a User is on.

function Find-CitrixUser {
    Param([string]$user,[string]$server,[string]$domain,[switch]$verbose)
    $type = [system.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeUser",$server)
    $mfuser = [system.Activator]::CreateInstance($type)
    $mfuser.Initialize(1,$domain,1,$user)
    Write-Host
    Write-Host "User: $($mfuser.UserName) found on the Following:"
    foreach ($s in $mfuser.Sessions)
    {
        if($verbose)
        {
            Write-Host
            Write-Host "$($s.ServerName)"
            Write-Host "-=-=-=-=-=-"
            Write-Host "AppName          : $($s.AppName)" -foregroundcolor yellow
            Write-Host "SessionName      : $($s.SessionName)" -foregroundcolor yellow
            Write-Host "SessionID        : $($s.SessionID)" -foregroundcolor yellow
            Write-Host "ClientAddress    : $($s.ClientAddress)" -foregroundcolor yellow
            Write-Host "ClientEncryption : $($s.ClientEncryption)" -foregroundcolor yellow
            Write-Host
            Write-Host "Processes"
            Write-Host "========="
            foreach ($proc in $s.Processes)
            {
                Write-Host $proc.ProcessName -foregroundcolor Green
            }
            Write-host
        }
        else
        {
            write-Host "   -> $($s.ServerName)"
        }
    }
}

« Prev