chgl
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:
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!
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:$_}
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!
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.
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 ?
Is sessionname not matches with username ?
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.
« 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$username=Read-Host "Please Enter Username "
foreach ($server in $servers )
{
logoff $username /server:$server
}