Avatar of GGHC
GGHC

asked onย 

Script to remotely kill process for a specific user on all Citrix servers

Looking for a script that can be used remotely to kill a specific process for a specific user on any server in the Citrix farm. ย 
Also is it possible that there can be an Input Box that I can enter the Username and process name?

Thanks in advance.
CitrixScripting LanguagesPowershell

Avatar of undefined
Last Comment
Sam Jacobs
Avatar of James Rankin
James Rankin
Flag of United Kingdom of Great Britain and Northern Ireland image

Use psexec
Avatar of James Rankin
James Rankin
Flag of United Kingdom of Great Britain and Northern Ireland image

Or pskill, I mean ๐Ÿ˜ƒ
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Are you looking to kill a process or a Citrix published application?
Avatar of Arana (G.P.)
Arana (G.P.)

or psexec to execute a taskkill
Avatar of GGHC
GGHC

ASKER

When I tried Taskkill it killed the process on the entire server not just for that user.

@Sam - It's a Citrix published app. It sometimes gives error which we need to end that process for that user session. But it's a long manual process.
Avatar of James Rankin
James Rankin
Flag of United Kingdom of Great Britain and Northern Ireland image

Yes, you need to maybe use something like pslist to identify the process ID and then kill it using that rather than the image name
Avatar of James Rankin
James Rankin
Flag of United Kingdom of Great Britain and Northern Ireland image

Don't you have Studio or Director where you can view the processes remotely and terminate them from the GUI? You didn't say what version of Citrix it was.
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

What version of Citrix are you running? 7.x?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of GGHC
GGHC

ASKER

Thank you all!

Big THANKS to oBdA. That script is extremely wicked! It's doing exactly what was needed in an amazing fashion! Wow
Avatar of Arana (G.P.)
Arana (G.P.)

So small yet so elegant, great code.
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

You might also want to try this (on a DDC):

$user = Read-Host "Enter user name (in domain\user format)"
$application = Read-Host "Enter published application to log off" 

Add-PSSnapIn Citrix*

$sessions = Get-BrokerApplicationInstance | ? {$_.applicationName -eq $application -and $_.username -eq $user}

if ($sessions.Count -gt 0) 
{ 
    Write-Host "The following sessions will be logged off:"
    $sessions | Select Username, MachineName, ApplicationName | ft -auto

    $confirm = Read-Host "Do you wish to continue? (Y/N)"
    if ($confirm -eq 'Y')
    {
        Foreach ($session in $sessions)
        {
            Stop-BrokerSession $session.SessionKey
        }
    }
} 
else
{
    Write-Host "There are no sessions matching your criteria."
}

Open in new window

Scripting Languages
Scripting Languages

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.

30K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo