Find-CitrixUser.ps1 (Citrix Top 10)
This is another script that I can use quite often. It is a simple script that queries all the sessions and returns the ones where the User matches. I made the User a RegEx search so you could do multiple users.
Name: Find-CitrixUser.ps1
Purpose: Finds where the user(s) are and outputs session info
-
# Find-CitrixUser.ps1
-
# Brandon Shell [MVP]
-
# www.bsonposh.com
-
# Finds where the user(s) are and out puts session info
-
Param($user=".*",[switch]$help)
-
function HelpMe{
-
Write-Host
-
Write-Host " Find-CitrixUser.ps1:" -fore Green
-
Write-Host " Finds where the user(s) are and out puts session info"
-
Write-Host
-
Write-Host " Parameters:" -fore Green
-
Write-Host " -User : Optional. Name of the User or RegEx (Default is all users)"
-
Write-Host " -Help : Optional. Displays This"
-
Write-Host
-
Write-Host " Examples:" -fore Green
-
Write-Host " Finds User TestMe and outputs and returns ServerName,ClientAddress, and SessionID" -fore White
-
Write-Host " .\Find-CitrixUser.ps1 | ft ServerName,ClientAddress,SessionID " -fore Yellow
-
Write-Host
-
Write-Host " Finds all Users who start with ‘Sales’ and returns UserName,ServerName, and SessionID" -fore White
-
Write-Host " .\Find-CitrixUser.ps1 `"^sales`" | ft UserName,ServerName,SessionID " -fore Yellow
-
Write-Host
-
Write-Host " To View All properties availiable." -fore White
-
Write-Host " .\Find-CitrixUser.ps1 <username> | Get-Member" -fore Yellow
-
Write-Host
-
}
-
-
# Check for the Help or if
-
if($help){helpme;Write-Host;return}
-
-
# Code to Get the Farm and Initialize
-
$farm = New-Object -com "MetaframeCOM.MetaFrameFarm"
-
$farm.Initialize(1)
-
-
# Get the Sessions and Parse for Users who match
-
$farm.Sessions | ?{$_.UserName -match $user}
tshell :: Apr.07.2008 :: All, Citrix, Powershell, SQL, Scripting :: No Comments »
