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

2 Comments

  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
  2. You can reboot the remote computer in the following way, with credentials from powershell:

    Restart-Computer -ComputerName -Force –user

    Ex:

    Restart-Computer -ComputerName tests -Force –user

    (it will ask you to enter the administrator credentials of the team in question)

    Post a Reply

Leave a Reply to blackbiz Cancel reply

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