Windows

How to logoff, restart, or shutdown Windows PC or Server remotely via Command Prompt and PowerShell

There are times you (System Administrator) may want to reboot your PC due to undesired behavior on your PC. During and after the installation of new programs (software and hardware), most times, you may need to restart your device. This will shut off all processes so that the Kernal can be re-established with the new software or hardware.

See the following guides on “how to prevent a remote shutdown and restart in Windows 10, how to allow only admin users (administrators) to shut down and reboot Windows Server 2012, how to prevent users from shutting down in a Virtual Machine and Handy Command-Prompt Shutdown Commands.

Mac is a Unix environment, everything is cleared during the ‘shut down’ and ‘restart" process, thereby clearing all processes, cache, and memory and, giving the device a complete start.

Note: Shutting down a computer is a way to power down all processes of the machine. “It’s very similar to a restart but with the exception that your computer won’t turn back on again until someone powers it up. The ways to shutdown Windows 10 are similar to the restart options. Here is a link on how to prevent users from shutting down your device. If you wish to allow automatic logon upon shutdown and restart, see the following link for the needed steps.

Why is a restart the preferred method when completing a new install or uninstall? And why is a computer restarts during Windows Operating System updates needed?
- Shutting down a Windows computer actually creates a deep hibernation file that the PC later leverages to allow for Fast Startup.
A restart, on the other hand, completely kills all processes, clears the RAM, and clears the processor cache.
- Shutting down a computer is a more energy-efficient and environmentally friendly way to leave a PC unattended
- Leaving a PC in sleep mode results in some power usage by the RAM and from the storage of open files and programs

Here are the steps to have your device shutdown and restarted: Windows has various ways to shutdown and restart remote computers natively via the Command Prompt as shown below.

1: Restart With a Custom Message: Open command prompt, and type the following commands below.

shutdown /m \techdA101 /r /c “Demonstration purpose"

I used multiple switches in this command e.g.
– /m is for remote Servers. RemoteServerName needs to be replaced by the name of my server above (techdara101) which you wish to.
– /r is for restart it can be replaced by /s if you want to shut down the server.
– To add a comment, use the switch /c followed by the message as shown below and press Enter on your keyboard when done.

2: Restart or shutdown the Server remotely: By using the command below, another dialogue box will open up as shown below, enter a comment, and press ok.

shutdown -i

3: Restart Remote Computer: By default, this will prompt the remote computer and give it about a minute before it restarts.

shutdown /r /m \techdA101

4: Immediate Restart no Countdown: If you want to immediately restart with no countdown or message use this command.

shutdown /r /m \techdA101 /t 0

5: Log user off remote computer: If you just want to log a user off, use the remote computer use this command.

shutdown /l /m\\techdA101

Via PowerShell: You can use PowerShell in a similar faction as CMD to have your remote PC restarted or shutdwn. Follow the steps discussed below.

1: Restart a computer: This command will immediately restart a remote computer. The -Force option will force a restart even if a user is logged on.

Restart-Computer -ComputerName techdA101 -Force

2: Shutdown a computer: This command will shut down a remote computer. Use the -Force to force a shutdown as shown below even if a user is logged on

Stop-Computer -ComputerName techdA101 -Force

3: Restart a list of computers: This is handy if you have several computers to restart. Just list all the computers you want in a text file and save it somewhere on your PC and add that to the PowerShell command as shown below.

restart-computer (get-content C:\Users\Christian\Desktop\listofcomputers.txt) 

4: Shutdown two devices: Us the following commands to have this task done.

Stop-Computer -ComputerName "techdA101", "techdA102"

Here are the various switches you’ll want to use in conjunction with this command to control the behavior. For a full list of commands, you can type the command below.

shutdown /?

Which will output several options including the following most commonly used options: The most common switches to use are the /r (to reboot) or /s (to shutdown).

/i   Display the graphical user interface (GUI). This must be the first option.
/m   \computer Specify the target computer.
/c   Print comment to screen of computer before rebooting or shutting down.
/l   Log off. This cannot be used with /m.
/s   Shutdown the computer.
/sg  Shutdown the computer. On the next boot, restart any registered applications.
/r   Full shutdown and restart (reboot) the computer.
/g   Full shutdown and restart (reboot) the computer. 
     After the system is rebooted, restart any     registered applications.
/a   Abort (cancel) a system shutdown.
/p   Turn off the computer with no time-out or warning.
/h   Hibernate the computer.
/fw  Combine with a shutdown option to cause the next boot to go to the firmware user interface.
/e   Document the reason for an unexpected shutdown of a computer.
/t xxx     Set the time-out period before shutdown to xxx seconds.
/f   Force running applications to close without forewarning users.

I want to point out that you’ll need the Remote Registry service enabled and started on the remote computer and the Windows Management Instrumentation (WMI) firewall rule enabled on the remote computer for this to work. You’ll also need to ensure your user account has administrator permissions on the remote computer or the command will fail.

Here are some links on how to shut down your device
https://techdirectarchive.com/2020/04/02/how-to-use-command-prompt-to-shutdown-restart-your-pc/
https://techdirectarchive.com/2020/01/19/unable-to-shutdown-a-vm-on-hyper-v/
https://techdirectarchive.com/2020/01/18/rive-off-welcome-screen-and-shutdown-screen/
https://techdirectarchive.com/2020/03/08/how-to-allow-all-users-to-shut-down-and-reboot-the-server-2012/

See this guide for “Windows Active Directory Administrative tools Shortcut command Keys” and this guide “Windows 10 Administrative Shortcut command keys.

I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x