If you are running Citrix or Microsoft RDS you know that occasionally, or sometimes frequently, user sessions get stuck and need an admin to kick them off. Or you have a ton of “disconnected” users taking up licenses preventing new sessions from starting, this generally requires an admin to login to the Citrix console, whether installed locally or on the server and find the disconnected users and disconnect them. Or they can run a PowerShell script to disconnect the users, which again either requires the admin to be logged in on the server or have all the necessary components installed on their local machine to run it remotely. Either way this is a manual task and requires someone with enough permissions to resolve the issue.
So what I have done is added a Self Service Request Offering in the Service Manager Self-Service Portal that kicks off an Orchestrator Runbook that perform the action for us. This allows even our Tier 1 helpdesk techs to kick off all disconnected users and also creates a service request which we can use for reporting on how many times we have to kick users off.
Before we dig into the meat and potatoes we need the Citrix SDK for our version of Citrix.
For Xenapp/Xendesktop 7+
http://www.citrix.com/go/citrix-developer/xenapp-xendesktop-developer-community/power-shell-xenapp7.html
For Xenapp 6.5
http://www.citrix.com/downloads/xenapp/sdks/powershell-sdk.html
Now install whichever version you have on your Orchestrator Runbook server(s). Note, it must be installed on all runbook servers if you have more than one.
Once that is installed you can run the following commands in PowerShell to verify installation:
add-pssnapin citrix*get-pssnapin citrix*
invoke-command -session $session -scriptblock {
script here
}
$RunAsPass = “subscribed, encrypted password”
$pass = $RunAsPass | ConvertTo-SecureString -AsPlainText -Force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $RunAsAccount, $pass
$session = New-PSSession -computername Citrixserver -Credential $credentials
invoke-command -session $session -scriptblock {
add-pssnapin citrix*
Get-xasession | where { ($_.state -eq “disconnected”)} | stop-xasession
}
remove-pssession $session
This is what it looks like in the Run .Net Activity.
This command will get all sessions where the state equals disconnected and remove the sessions.
This is what my runbook looks like.