Jump to content
Welcome to our new Citrix community!
  • 0

How to programmatically retrieve and kill the running (active or disconnected) session from Citrix Cloud

Brijesh Shah1709161754


Hi Team,


We have recently moved to the Citrix Cloud. However, we have good experience working with Citrix On-Prem. As part of existing functionality (for our own portal) we have some area where our users can see their running citrix sessions and not only that they can kill that as well.

For this, we used to run Get-BrokerSession -AdminAddress


However, after moving to Citrix Cloud we understood that we have to create API profile which gives us API Key and API Secret.

We need to use Set-XDCredentials and then Get-XDAuthentication to get authenticated with the profile.

Finally we need to run Get-BrokerSession (without AdminAddress) 


We ran this and it's working fine and I am able to see the list of all the sessions in my PowerShell ISE

However, the same command I ran through the ProcessInfo or C# (executing the powershell) it's failing with the following error 


Get-BrokerSession : Failed to connect to back-end server 'localhost' on port 80 using binding WSHttp. The server may
be off-line or may not be running the appropriate service


I have checked if I can pass the object comming from Get-XDAuthentication to Get-BrokerSession as I am thinking that Get-BrokerSession is not using the same session.

But neither Get-XDAuthentication give any output nor Get-BrokerSession has any argument to get that.


So, I am not sure what is failing but we are not able to use this programmatically.

Based on Citrix Support, REST API support to get the session and kill the session is not available.


Here is the code, I tries  


                var outputString = "";
                var exePath = ConfigurationManager.AppSettings["pathOfExe"];
                var ps1File = ConfigurationManager.AppSettings["pathOfPSFile"];

                var startInfo = new ProcessStartInfo
                    FileName = exePath,
                    Arguments = $"-NoProfile -ExecutionPolicy Bypass -File \"{ps1File}\"",
                    UseShellExecute = false

                using (var process = new Process())
                    process.StartInfo = startInfo;

                    var output = process.StandardOutput.ReadToEnd();
                    var errors = process.StandardError.ReadToEnd();

                    if (!string.IsNullOrEmpty(output))
                        outputString = output;

                        Console.WriteLine($"Output: {outputString}");

                    if (!string.IsNullOrEmpty(errors))
                        Console.WriteLine($"Error: {errors}");


ps1 file in PowerShell ISE is working without any issue. 

The content in that file is here.


Add-PSSnapin Citrix.*

Set-XDCredentials -CustomerId '{customerid}' -ProfileType CloudApi -StoreAs 'cc-euportalapi' -APIKey '{apikey}' -SecretKey '{apisecret}'
Get-XDAuthentication -ProfileName 'cc-euportalapi'
Get-BrokerSession -UserName '{someusername}'

Link to comment

1 answer to this question

Recommended Posts

  • 0



Have you by any chance enabled 2 factor authentication lately? My testing shows that MFA breaks creating new profiles, but existing ones "might" work.


When you get the Failed to connect error, it means that the Profiles does not work.


Please use a new VM or delete the existing profiles (Citrix Cloud SDK needs to be installed) and run the following:


asnp Citrix*



That will ask you to authenticate and successfully connect and list Broker Catalog.







Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...