-
#########################################
-
#### Citrix App Functions ####
-
#########################################
-
## Returns Citrix Application for Farm
-
## -Server: Name of Farm Server. This is required
-
## -App: Name of Application to remove. This is required
-
function Get-CitrixApp{
-
Param($Server =$(throw ‘$Server is Required’),$App= $(throw ‘$FarmServer is Required’))
-
$type =
[System.
Type]::
GetTypeFromProgID("MetaFrameCOM.MetaFrameApplication",
$Server)
-
$mfApp =
[system.
Activator]::
CreateInstance($type)
-
$mfApp.Initialize(3,"Applications\$myapp")
-
$mfApp.LoadData($true)
-
$mfApp
-
}
-
-
## Returns Users currently using APP
-
## -app: Name of Application. This is required
-
## -Server: Name of Farm Server. Defaults to local if not passed
-
## -count: Switch… if set just returns count of servers
-
function Get-CitrixAppUsers {
-
Param($app = $(throw ‘$app is required’),$server,[switch]$count)
-
function gcf{
-
param($srv)
-
$type =
[System.
Type]::
GetTypeFromProgID("MetaframeCOM.MetaframeFarm",
$Server)
-
$mfarm =
[system.
Activator]::
CreateInstance($type)
-
$mfarm.Initialize(1)
-
return $mFarm
-
}
-
$ErrorActionPreference = "SilentlyContinue"
-
Write-host
-
if($server){$mfm = gcf $server}
-
else{$mfm = New-Object -com MetaFrameCOM.MetaFrameFarm;$mfm.Initialize(1)}
-
$users = $mfm.Applications | ?{($_.AppName -eq $app) -or ($_.BrowserName -eq $app)}
-
$Users = $users.Sessions | sort -Property UserName
-
if($count){
-
Write-Host "Found [$($Users.Count)] Users for Application [$app]" -ForegroundColor White
-
Write-Host
-
}
-
else{
-
Write-Host ""
-
Write-Host "Found [$($Users.Count)] Users for Application [$app]" -ForegroundColor White
-
Write-Host "—————————————————–" -ForegroundColor gray
-
foreach($user in $Users){
-
If($User.SessionState -eq 1){
-
Write-Host ($User.UserName).PadRight(10) -ForegroundColor Green -NoNewline
-
}
-
else{
-
Write-Host ($User.UserName).PadRight(10) -ForegroundColor yellow -NoNewline
-
}
-
}
-
Write-Host
-
Write-Host "—————————————————–" -ForegroundColor gray
-
Write-Host "Found [$($Users.Count)] Users for Application [$app]" -ForegroundColor White
-
Write-Host
-
}
-
}
-
-
## Returns Servers currently published APP
-
## -app: Name of Application. This is required
-
## -Server: Name of Farm Server. Defaults to local if not passed
-
## -count: Switch… if set just returns count of servers
-
function Get-CitrixAppServers {
-
Param($app = $(throw ‘$app is required’),$Server,[switch]$count)
-
function gcf{
-
param($srv)
-
$type =
[System.
Type]::
GetTypeFromProgID("MetaframeCOM.MetaframeFarm",
$Server)
-
$mfarm =
[system.
Activator]::
CreateInstance($type)
-
$mfarm.Initialize(1)
-
return $mFarm
-
}
-
if($server){$mfm = gcf $server}
-
else{$mfm = New-Object -com MetaFrameCOM.MetaFrameFarm;$mfm.Initialize(1)}
-
$Apps = $mfm.Applications | ?{($_.AppName -eq $app) -or ($_.BrowserName -eq $app)}
-
# for XP farms
-
$servers = $apps | %{$_.Servers} | sort -Property ServerName | Select-Object ServerName
-
if(!$servers){
-
# for 40/45 farms
-
$servers = $Apps.Sessions | Select-Object ServerName | Sort-Object -unique ServerName
-
}
-
if($count)
-
{
-
Write-Host
-
Write-Host "Found [$($Servers.Count)] Servers for Application [$app]" -ForegroundColor White
-
Write-Host
-
}
-
else
-
{
-
Write-Host ""
-
Write-Host "Found [$($Servers.Count)] Servers for Application [$app]" -ForegroundColor White
-
Write-Host "———————————————–" -ForegroundColor gray
-
foreach($server in $servers){Write-Host "$($server.ServerName)" -ForegroundColor Green}
-
Write-Host "———————————————–" -ForegroundColor gray
-
Write-Host "Found [$($Servers.Count)] Servers for Application [$app]" -ForegroundColor White
-
Write-Host ""
-
}
-
}
-
-
## Returns Server(s) user is logged into via Citrix
-
## -LoginName: Login Name of user (Domain\User). This is Required
-
## -Server: Name of Farm Server. Defaults to local if not passed
-
## -Verbose: Details about User
-
function Find-CitrixUser {
-
Param([string]$LoginName,
$Server,
[switch]$verbose)
-
$user = $LoginName.Split("\")[1]
-
$Domain = $LoginName.Split("\")[0]
-
if($server)
-
{
-
$type =
[System.
Type]::
GetTypeFromProgID("MetaframeCOM.MetaframeUser",
$Server)
-
$mfuser =
[system.
Activator]::
CreateInstance($type)
-
$mfuser.Initialize(1,$Domain,1,$user)
-
}
-
else
-
{
-
$mfuser = New-Object -ComObject MetaframeCOM.MetaframeUser
-
$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)"
-
}
-
}
-
}