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.
# RDR # Recupere et fermer les sessions actives et reboot le serveur 
# Compatible RDS 2012 avec serveur BROKER 
# 
# 
$ServerBroker = "" 
$ServerHost = "" 
$Sessions = Get-RDUserSession -ConnectionBroker $ServerBroker 
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 
} 
Restart-Computer

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.


How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!



Related Posts


Install and use the Admin Center on Windows 10
Presentation In this tutorial, we will see how to install the Admin Center on a computer running Windows 10. The Admin Center is the new name of the Honolulu Project that allows the administration of servers from the Windows Server 2008R2 version and

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 access the reader by the browser directly entering

Active Directory: Joining a Computer to a Domain at the Command Line
Introduction The Active Directory domain join of a computer can be done using either the GUI or using command line and PowerShell. In this tutorial, I will explain how to join a computer to a domain using the various command lines that are: NETDOM DJ