[THIN] Re: Powershell for Self Service User Logoff of all XenApp 6.5 sessions

  • From: marcus <marcus@xxxxxxxxxxxxxx>
  • To: thin@xxxxxxxxxxxxx
  • Date: Fri, 19 Sep 2014 18:18:43 +0200



James Scanlon wrote:
Hey All,
I want to write a script that we can publish to the end user (a
published self service app??) that allows the end user to log themselves
and all their Citrix sessions off completely on our XA6.5 farm.

Basically a click here to kill everything in Citrix if you cant access
something and its 2am and the service desk are not available.
There is lost of ideas out there, but was unable to find a 'whole of
farm' logoff - or indeed a program that says - "Hello user, you are
logged into servers X y Z, select the ones to stop and click next"....

I am not much of a powershell scripter and after some searching and much
trial and error I have gotten this far with the script,
It seems to work sometimes, getting all the sessions for the user, other
times it gets none but Ibelieve its killing the session the script is
being run under so its then unable to get to the other sessions and
terminate them. I also still need to variablise the user name part too?

Any one got any advice, ideas or tools that might help it would be
greatly appreciated. :)

Add-Pssnapin Citrix*
Get-XASession -Farm | Where-Object { $_.AccountName -match
"Fred.Flintstone" } | stop-xasession
Shure with powershell? How do you get around the per user startup time?

Around the beginning of june we had a similar topic in the list, topic was "session kill": //www.freelists.org/archive/thin/06-2014

I've modified the script a litte more to our customer and adminitrators needs, some logging and some more user feedback.

Delete \\ and linebreaks!

@echo off
set  stampname=%date:~6,4%%date:~3,2%%date:~0,2%-%\\
time:~0,2%%time:~3,2%%time:~6,2%_%username%
set kicklogfile=\\store\share$\%stampname%.log
set SRVLIST=\\store\share$\ctx-workers.lst
@echo KICK %USERNAME% FROM:
for /f %%i in (ctx6-workers.lst) do (
@echo scanning Server %%i
quser "%USERNAME%" /server:%%i 2>NUL | find /i "%USERNAME%" > \\
%TEMP%\%%i.txt
for /f "tokens=2" %%j in (%TEMP%\%%i.txt) do (
@echo SERVER %%i >> %kicklogfile%
qprocess "%username%" /Server:%%i >> %kicklogfile%
@logoff %%j /server:%%i /V
REM for /f "tokens=2" %%j in (%TEMP%\%%i.txt) \\
do @echo %%j /server:%%i
))
msg %USERNAME% /TIME:10 /W < %KICKLOGFILE%


Configure \\store\share$ to your needs
place your citrix servers into ctx-workers.lst, one per line

Publish the script from a server the users don't use for any other application, so the script is guaranteed to run in a clean session. From my experience since june - the script is working fine in more than 90 %. The few where it hasn't worked as it should have done: not shure - 1st level support doesn't ask, the customers won't tell what they've done (aside of restarting local computers several times because of a published application has thrown an error.... )

hth, Marcus




Cheers
scanjam

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Other related posts: