How to Restart Windows Server using Powershell

restart windows server

If you’re looking for a simple guide on how to restart server processes properly, this article will walk you through every step. Rebooting a Windows Server is a trivial task, and it is regularly needed after several events such as upgrades, changes in configuration, and issues with performance. A reboot properly terminates processes and unmanaged resources, nullifies memory, reloads services, and stabilizes the system. Not rebooting in a timely fashion can contribute to slower processes and services not being available.

PowerShell enables an easy and scriptable approach to rebooting a host (server). It allows for rebooting a server with no manual intervention and reasonably shortens downtime by allowing for automation or remote execution. The administrator can reboot one or more servers while not needing to use a GUI or an external application.

This option is supported on all Windows Server versions 2016, 2019, and 2022. PowerShell supports both local and remote reboots which is ideal for an administrator with physical or virtual servers in a larger scale enterprise like environment.

In this article, we will explain step-by-step with examples how to reboot a server using PowerShell, both locally and remotely.

Prerequisites Before Restarting Windows Server

Before restarting a Windows Server using PowerShell, confirm that the following technical requirements are met.

1. Administrator Privileges

You must run PowerShell as an administrator. Right-click on the PowerShell icon and select “Run as administrator”. Without elevated permissions, restart commands will fail.

2. Execution Policy

PowerShell must allow script execution. To check the current policy, run:

Get-ExecutionPolicy
Get PowerShell Execution Policy Status

If the output is restricted, change it using:

Set-ExecutionPolicy RemoteSigned
Successful execution of Set-Execution Policy Remote Signed in PowerShell

Type Y and press Enter to confirm. This change allows locally written scripts to run while blocking unsigned remote scripts.

3. PowerShell Remoting for Remote Restart

To restart a server remotely, enable remoting on the target machine:

Enable-PSRemoting -Force
Enable-PSRemoting -Force executed successfully in PowerShell to enable remote management

This command starts the WinRM service, sets the startup type to automatic, and configures the firewall. Run it in an elevated PowerShell session on the target server.

These steps prepare both local and remote environments for safe and successful restarts using PowerShell.

Basic PowerShell Command to Restart a Local Server

To restart server from command line using PowerShell, use the Restart-Computer cmdlet. It works for local Windows Servers and requires admin privileges. This command performs a clean shutdown followed by a reboot. It is the standard PowerShell restart command for local systems.

Basic Syntax:

Restart-Computer
Restart-Computer command executed in PowerShell to reboot the system

Running this command in an elevated PowerShell session will gracefully restart the server. It closes running applications, stops services, and initiates a safe reboot process.

Optional Parameters:

Sometimes, the system might not restart because an application is frozen or not responding. If that happens, you can force the reboot using:

Restart-Computer -Force
Restart-Computer -Force command executed in PowerShell to force system reboot without prompt

This option skips the wait and forces everything to close immediately.

If you want to double-check before the system restarts, you can include the -Confirm flag. This prompts you to approve the action before it runs:

Restart-Computer -Confirm

If you want to preview what the command would do without actually restarting the server, you can use the -WhatIf flag:

Restart-Computer -WhatIf

It shows the expected outcome without executing anything, which is useful when testing scripts.

Restarting a Remote Windows Server Using PowerShell

To restart a remote Windows Server, you can use the same Restart-Computer cmdlet with the -ComputerName parameter. Just replace “ServerName” with the name or IP address of the target machine:

Restart-Computer -ComputerName "Server01"

This will send a remote restart request to the specified server. Make sure PowerShell remoting is enabled on the remote system.

If your current session doesn’t have permission to access the remote server, add the -Credential flag to supply a valid username and password:

Restart-Computer -ComputerName "Server01" -Credential (Get-Credential)

This will prompt you to enter login credentials for the remote machine.

You can also use Enter-PSSession to connect directly to a remote server and run commands interactively:

Enter-PSSession -ComputerName "Server01"
Restart-Computer

Or use Invoke-Command to send a restart instruction without entering a full session:

Invoke-Command -ComputerName "Server01" -ScriptBlock { Restart-Computer -Force }

Before using any of these methods, ensure that Windows Remote Management (WinRM) is enabled and that the firewall allows remote PowerShell traffic. These steps are required for a successful remote restart using PowerShell.

Restarting Multiple Servers at Once

To perform a batch restart across multiple servers, you can pass an array of server names to the Restart-Computer cmdlet. This is useful in enterprise environments where you manage many systems at once.

Here’s a simple PowerShell script for server restart in bulk:

$servers = @("Server1", "Server2")
Restart-Computer -ComputerName $servers -Credential (Get-Credential)

This command prompts for credentials and then sends a restart request to all listed servers. PowerShell processes the restart in parallel, saving time and effort.

Using this method helps automate regular maintenance or apply updates across several machines without logging into each one manually. It’s efficient, especially when dealing with dozens or hundreds of servers in a network.

Scheduling a Restart Using PowerShell

To schedule a reboot during off-hours, you can use the Task Scheduler through PowerShell with the schtasks.exe utility. This is helpful during maintenance windows or after update deployments when you want to avoid service disruptions.

Here’s an example that sets up a scheduled reboot at 2:00 AM:

schtasks.exe /Create /SC ONCE /TN "ScheduledRestart" /TR "shutdown.exe /r /f /t 0" /ST 02:00 /RU "SYSTEM"

This command creates a one-time task named “ScheduledRestart” that forces a reboot at 2:00 AM, using the system account.

You can also run this from a PowerShell script to automate reboots across multiple servers as part of a patching process. It’s a reliable way to handle reboots without manual intervention.

Handling Errors During Restart

When restarting a server with PowerShell, you may encounter errors like Access Denied or RPC Server Unavailable. These issues often result from missing admin rights, firewall restrictions, or remoting not being enabled.

To handle such restart failures, wrap your command in a Try-Catch block:

try {
    Restart-Computer -ComputerName "Server01" -Credential (Get-Credential)
} catch {
    Write-Error "Restart failed: $_"
}

This approach catches any error and prints a clear message instead of stopping the script.

Also, verify that required services like WinRM are running and that no active user sessions or service dependencies are blocking the restart.

Verifying Server Status After Restart

After restarting a server, it’s important to confirm it came back online. You can use the Test-Connection cmdlet to ping the server and check its availability:

Test-Connection -ComputerName "Server01" -Count 2

To automate the check, use a loop that pings until the server responds:

do {
    Start-Sleep -Seconds 5
} until (Test-Connection -ComputerName "Server01" -Quiet)

This waits in 5-second intervals until the server is reachable.

You can also run Get-Service remotely to verify if critical services are running:

Get-Service -ComputerName "Server01"

These simple checks help verify the reboot was successful and confirm the system is healthy. Use them as part of your server health check routine after every restart.

PowerShell Script Example: Full Restart Workflow

Here’s a complete PowerShell reboot script that restarts a remote server, handles errors, and checks when it comes back online:

$server = "Server01"
$cred = Get-Credential

try {
    Restart-Computer -ComputerName $server -Credential $cred -Force
    Write-Output "Restart command sent to $server"
} catch {
    Write-Error "Restart failed: $_"
    exit
}

# Wait for server to respond
do {
    Start-Sleep -Seconds 5
    $online = Test-Connection -ComputerName $server -Quiet
} until ($online)

Write-Output "$server is back online"

This script automates restart, includes error handling, and confirms the server is back up. It uses Restart-Computer, Try-Catch, and Test-Connection to cover the full cycle.

You can also extend this script to write output to a log file or send an email notification for tracking purposes.

Conclusion

Restarting a Windows Server using PowerShell is a reliable and flexible approach for both local and remote systems. You’ve seen how to use the Restart-Computer cmdlet, handle multiple servers, schedule reboots, manage errors, and confirm that systems are back online. Each method supports specific needs—from one-time restarts to full automation scripts.

Choose the method that matches your environment. For single servers, a basic command may be enough. For large networks, automated scripts with error checks and scheduled tasks offer better control. PowerShell’s remote capabilities and scripting features save time, reduce manual work, and ensure consistency across your server infrastructure.

Experience UltaHost’s affordable Windows VPS hosting for smooth server management and reliable performance. UltaHost gives you full control with automated tools like PowerShell, while ensuring stable uptime and expert support every step of the way!

FAQ

How do I restart a Windows Server using PowerShell?
Can I restart a remote Windows Server with PowerShell?
What are the prerequisites for remote restart using PowerShell?
How can I force a restart if an application is not responding?
Can I schedule a server restart using PowerShell?
How do I confirm if the server came back online after a restart?
What should I do if the restart command fails?

Related Post

How to Set Up React Native on Windows

React Native is an open-source framework developed by F...

How to Install AnyDesk on Windows

AnyDesk has become a popular choice for remote desktop ...

How to Install PyCharm on Windows

PyCharm is a powerful Integrated Development Environmen...

How to Install RubyMine on Windows

RubyMine is an integrated development environment (IDE)...

How to Install R Language on Windows

R is a popular programming language and software enviro...

How to Connect to Windows VPS from an Android...

Remote access to your Windows VPS stands for Virtu...

Leave a Comment