Link to home
Start Free TrialLog in
Avatar of pauledwardian
pauledwardian

asked on

Powershell to Logoff terminal session

I need a powershell script that would log off a specific user from the terminal server. Can someone please help...
Avatar of becraig
becraig
Flag of United States of America image

Here is a quick dirty method

$sessions = qwinsta /server servername

foreach ($session in $Sessions)
{
#do a split for the values returned which are fixed and assign a variable to it
I can code that if you want me to
Then an if statement if they match e.g.

if ($newvariable -like "*username*")
{
#run rwinsta and disconnect the session by session id which you get from the previous

}

There are many other ways but this is a quick and dirty idea, if you want an actual complete script let me know.
There is a powershell module you can get http://archive.msdn.microsoft.com/PSTerminalServices
but what I have above will work as is with no additional downloads or installs.
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pauledwardian
pauledwardian

ASKER

thanks