Wednesday, October 28, 2015

Powershell Remote Goodies (RDP Shutdown Query)

I had cause this morning to reboot a remote server that was unresponsive to RDP sessions.  The server is running Windows 2003 (yes, yes I know.. )  So new RDP session would hang at Applying settings so I looked to POSH to take care of this.

A couple things I discovered that I'd not heard of before.. Quesry session, and MSG.

First off to see what users had sessions:
Query Session /server:"servername"

It will list all current sessions whether Active or otherwise. Very nice.

Next is MSG.

The MSG command sends a message just like the old NET SEND did.  So first thing to notify the few users who had working sessions that the server was going down.

(I didnt even need to use my admin account for this)
MSG /server:"server name" *
Enter message to send; end message by pressing CTRL-Z on a new line, then ENTER.

Easy as cake.. even my RDP session that was still Applying Settings got the notice. So next step to actively tell it to reboot.

First thing I tried was
Shutdown /r /m \\servername /force

Which didn't work because I did not have the right permissions.  Next was running POSH as my admin account, when I retried the command it wanted a reason code.

Reasons on this computer:
(E = Expected U = Unexpected P = planned, C = customer defined)
Type    Major   Minor   Title

 U      0       0       Other (Unplanned)
E       0       0       Other (Unplanned)
E P     0       0       Other (Planned)
 U      0       5       Other Failure: System Unresponsive
E       1       1       Hardware: Maintenance (Unplanned)
E P     1       1       Hardware: Maintenance (Planned)
E       1       2       Hardware: Installation (Unplanned)
E P     1       2       Hardware: Installation (Planned)
  P     2       3       Operating System: Upgrade (Planned)
E       2       4       Operating System: Reconfiguration (Unplanned)
E P     2       4       Operating System: Reconfiguration (Planned)
  P     2       16      Operating System: Service pack (Planned)
        2       17      Operating System: Hot fix (Unplanned)
  P     2       17      Operating System: Hot fix (Planned)
        2       18      Operating System: Security fix (Unplanned)
  P     2       18      Operating System: Security fix (Planned)
E       4       1       Application: Maintenance (Unplanned)
E P     4       1       Application: Maintenance (Planned)
E P     4       2       Application: Installation (Planned)
E       4       5       Application: Unresponsive
E       4       6       Application: Unstable
 U      5       15      System Failure: Stop error
E       5       19      Security issue
 U      5       19      Security issue
E P     5       19      Security issue
E       5       20      Loss of network connectivity (Unplanned)
 U      6       11      Power Failure: Cord Unplugged
 U      6       12      Power Failure: Environment
  P     7       0       Legacy API shutdown

I re-ran the command but by this time the local staff had powered it off since it was not responding to a shutdown at the console either. :(

But I did learn some new things today.

No comments:

Post a Comment