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
}
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)"
}
}
}
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)"
}
}
}
tshell :: Jun.13.2007 :: Citrix, HowTo, Powershell, Scripting :: No Comments »

You really really helped me out when you put the multi-farm thing together. I took that seed and wrote an expanded function called Get-CTXFarm that I thought you might like to check out. I yet to run a field test, but I built each section after figuring out the bits live so I am pretty sure it will work. Please let me know your feedback. Here is the link: http://merddyin.spaces.live.com/