This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
It almost all works great. When I have the server written in, it works properly, but when I switch it to a variable so I don't have to have a company specific PS command it gives me weird error.
Image version This first one said access denied because I'm just logged in as a regular domain user instead of domain admin so that's good that it worked. Second command said my syntax is wrong and i don't know why https://i.imgur.com/lY6Vhz9.png
Text versions: Working:
$UserTSO=Read-Host -Prompt 'Input the user logon name';#USERTSO=User to sign off
$Server1=Read-Host -Prompt 'Input the hostname or IP address of the server';#Server1= Server the user has an RDP Session to
$users = query user $USERTSO /server:192.168.1.11;#Command to determine which user and server's session to kill
$IDs = @() ;
for ($i=1; $i -lt $users.Count;$i ) { $temp = [string]($users[$i] | Select-String -pattern "\s\d \s").Matches ; $temp = $temp.Trim() ; $IDs = $temp ; }
logoff $IDs /server:192.168.1.11;
Input the user logon name: administrator Input the hostname or IP address of the server: 192.168.1.11 Could not logoff session ID 1, Error code 5 Error [5]:Access is denied.
Not working at all:
$UserTSO=Read-Host -Prompt 'Input the user logon name';#USERTSO=User to sign off
$Server1=Read-Host -Prompt 'Input the hostname or IP address of the server';#Server1= Server the user has an RDP Session to
$users = query user $USERTSO /server:($Server1);#Command to determine which user and server's session to kill
$IDs = @() ;
for ($i=1; $i -lt $users.Count;$i ) { $temp = [string]($users[$i] | Select-String -pattern "\s\d \s").Matches ; $temp = $temp.Trim() ; $IDs = $temp ; }
logoff $IDs /server:($Server1);
Input the user logon name: administrator
Input the hostname or IP address of the server: 192.168.1.11
Invalid parameter(s)
Display information about users logged on to the system.
QUERY USER [username | sessionname | sessionid] [/SERVER:servername]
username Identifies the username.
sessionname Identifies the session named sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).
Invalid session ID 192.168.1.11
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/sysadmin/co...