Link to home
Start Free TrialLog in
Avatar of chgl
chglFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PowerShell Log off Script

HI Guys,

We have 3 RDS or terminal servers, and i am trying to write a script to logg an individual user off when i need to so far this is what i have writ:

$servers="server-rds01","server-rds02","server-rds03"

$username="Read-Host "Please Enter Username "

$servers | foreach {qwinsta $username /server:$_}

Open in new window


when i run the script the window closes automatically and also i dont know what to write in that code to logg that user off. Please help!
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

$servers="server-rds01","server-rds02","server-rds03"

$username=Read-Host "Please Enter Username "

foreach ($server in $servers )
{
  logoff $username /server:$server
}
Avatar of chgl

ASKER

thats doesn't work. The logoff function only accepts these parameters, it does accept username:

PS C:\Documents and Settings\k.uddin> logoff /?
Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]

  sessionname         The name of the session.
  sessionid           The ID of the session.
  /SERVER:servername  Specifies the Terminal server containing the user
                      session to log off (default is current).
  /V                  Displays information about the actions performed.
what is the error in this case?  
Is sessionname not matches with username ?
Avatar of chgl

ASKER

no
Check out the following articles:

« removed - Qlemo, Topic Advisor »

Terminal Services PowerShell Module

The PSTerminalServices module should do the job. The other option is to try using the query.exe or quser.exe, which are native in Windows Server 2003 Terminal Server, but I'm not sure about 2008.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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