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...
PowershellScripting LanguagesShell Scripting

Avatar of undefined
Last Comment
pauledwardian

8/22/2022 - Mon
becraig

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.
becraig

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
becraig

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
pauledwardian

ASKER
thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck