PowerShell: Restart Fails ‘Other Users Logged On’

KB ID 0001374

Problem

If you intend to shutdown, or restart a remote computer using PowerShell, you may see the following error message;

PS C:\> Restart-Computer “Computer-name
Restart-Computer : This command cannot be run on target computer(‘Computer-name’) due to following error: The system shutdown cannot be initiated because there are other users logged on to the computer.
At line:1 char:1
+ REstart-Computer “Computer-name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Computer-name:String) [Restart-Computer], InvalidOperationException
+ FullyQualifiedErrorId : RestartComputerFailed, Microsoft.PowerShell.Commands.RestartComputerCommand

Solution

You need to add the -Force flag to the command like so;

PowerShell Restart Users Logged On

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

1 Comment

  1. It is a fact that Windows administrators periodically need to reboot servers and desktops. Because of this fact, I always was running into scripts that would remotely reboot a group of computers. But in PowerShell, this is now (dangerously) easy and no scripting is required. All we need is the Restart-Computer cmdlet. The Restart-Computer cmdlet will fail, if a logon session is detected. PowerShell will raise an exception. However, you can force a reboot using — what else? — the -force parameter. Be aware this will force applications to close with the potential loss of unsaved work.

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *