Restart an RDS server member of a farm

This script allows you to reboot a server RDS member of a farm with a broker session by closing the still open sessions.

Use :

  • Change the two variables $ServerBroker and $ServerHost.
  • Create a scheduled task by running the script on the remote desktop session host server.
# Get close and active sessions of a desktop session host server remotely and reboot the server
# Compatible with RDS farms 2012R2 / 2016/2019

$ServerBroker = "Broker.dom.local"
$ServerHost = "RDH-01.dom.local"

# Get sessions from broker
$Sessions = Get-RDUserSession -ConnectionBroker $ServerBroker

# Browse all open sessions and close sessions on the session host server configured in parameter
foreach($Session in $Sessions){

    #Write Event
    Write-EventLog -LogName "System" -Source "EventLog" -EventId 6013 -EntryType Information -Message "$Session.UserName close session"

	# Write-Host $Session.UnifiedSessionID -ForegroundColor Red
	Invoke-RDUserLogoff -HostServer $ServerHost -UnifiedSessionID $Session.UnifiedSessionID -Force


Using the script avoids ending up with xxxxx.BACKUP-Y folders in the server’s C: \ Users folder.

During a reboot if UPDs are still mounted a temporary folder is created for each session still open.

Related Posts

MDT: Running a PowerShell Script During a Deployment

In this article, I explain how to run a PowerShell script (ps1 file) during a deployment with MDT. Copy the ps1 << 1 >> file to the Scripts folder in the folder. Open the properties of the

GPO hide drive C

Presentation In this tutorial, we'll see how to hide drive C using Group Policy (GPO). This GPO is often used to hide drives on RDS farms. Hiding the reader does not prevent access, it is possible to

Publish RemoteApp 2008R2 on a Farm RDS 2012R2 / 2016/2019

Presentation In this article, I will explain how to publish RemoteApp applications from an RDS server running Windows 2008R2 on a RDS 2012,2016 or 2016 farm. Prerequisites An RDS server running Window