Monday 5 March 2012

Script to find all the disconnected sessions in citrix servers

I know the effort in logging into all the citrix servers for disconnected sessions and logging them off everyday. So I have designed a batch script which would run the qfarm command in all the servers mentioned in the text file and output the result to a text file. Here goes my script:

@echo off
Title Developped by Chaitanyakumar G
cd \
cd %userprofile%\Desktop\Servers
del /q *
cd \
cd %userprofile%\Desktop\Apps
for /f %%i in (hostnames.txt) do psexec.exe \\%%i -u Domain\username -p UR_PWD cmd /c "qfarm %%i /disc" >> .\Servers\%%i_Applications.txt
pause

In ur desktop, create a folder called Servers where all your servers text files would be created. Create an other folder called Apps where you need to have psexec.exe(you can download it from here). Here you need to create a text file hostnames.txt and place all your citrix servers, no matter which farm they belong to. As this script takes the hostnames from the text file hostnames.txt, we can place all the citrix servers here. Now copy the above script and place it in Apps folder. Now double click it. Once the script is executed, in the Servers folder we can see list of files. We can see all the files here. View by details in the folder view to find the size of the text files. If size of text file is zero, it shows that there are no disconnected sessions for that particular server. If size is more than zero, it shows that there are disconnected sessions. Now login to that particular server and clear the disconnected sessions. In the text file you can also see the application name. So, you can directly open that particular application and disconnect the sessions. This script will be useful if you have lot of citrix applications and servers.

If you still want to reduce the administrator effort, execute the script and once you get the text files in Servers folder, download tslogoff.exe(download it from here). Go through the Readme.txt file about the usage and logoff the disconnected sessions by connecting to the server using psexec.exe

No comments:

Post a Comment

Next previous home