Powershell - Logoff disconnected sessions
-
I'm trying to write something that will go through our Citrix server and "log off" all the disconnected sessions.
I can do this fine manually through PowerShell fine and works, but now I want to automate it so I can run it or even schedule it to run every X minutes/hours.
(Just trying it on 1 servers at the moment, I'm outputting the array(s) etc to check the results of the commands.
)$servername = "xen30"
$pc = qwinsta /server:$servername | select-string "Disc" | select-string -notmatch "services"
$pc
That gives me a array :-crav2 878 Disc
ryan 881 Disc
lanc4 885 Disc
clive 888 Disc
treg1 889 Disc
rob 891 Disc
paul 892 Disc
New2 893 DiscThe command i'm using is
logoff <id> /server:$servername
So what I need to do is "extract" the 2nd colum form the $pc list that gives me a list of id's then I guess use the
foreach
command to "inject" the ids into the logoff command. -
-
-
not having much luck...... It's Friday so giving up till Monday/Tuesday