RDS/Terminalserver message/notification to all active users

RDS/Terminalserver message/notification to all active users

RDSMessenger.ps1

UPDATE 11/09/2019: If you like this script as module or EXE see my new post

In RDServer (Remote Desktop) environmets (also know with the legacy name terminalservices) you need to notify all active users, because there is a maintenace or anything else. I searched a while to find a thin solution for that, but did not find any proper solution. So I decided to write a short powershell script to do this task.
With Windows Server 2012 a new cmdlet was introduced
https://docs.microsoft.com/en-us/powershell/module/remotedesktop/send-rdusermessage?view=win10-ps
Send-RDUserMessage

The goal:

Link to my github repository:
https://github.com/blog-it-koehler-com/rdsmessenger

You can use this cmdlet after importing on the server where you want so send the notification. This message is also displayed in remoteapps so it can be used in mixed environments with desktop and remoteapps. (WIN2012/R2, WIN2016 and WIN2019 include this module by default).

NOTE: how to find the RD-Broker? If you don’t know which server is the broker, please open your ServerManager and connect all server which are part of the collection (ServerManager tells you which one is missing)
After importing all server in ServerManager you can see the configuration and also the broker

As mentioned there is one cmdlet which generates the message for one user. The heart of my script are these few lines:

Import-Module RemoteDesktop
$broker = "FQDN of the Broker"
$userids = Get-RDUserSession -ConnectionBroker "$broker" | sort Username
foreach($uid in $userids){
            $id = (($uid).UnifiedSessionID)
             Send-RDUserMessage -HostServer $broker -UnifiedSessionID $id -MessageTitle "messagetitel" -MessageBody "text in your messagebox"
             }

With the following script you see some output when you execute the script.

Import-Module RemoteDesktop
#fill message
$msgtitel = Read-Host "Type message titel"
$msg = Read-Host "Type message..."
$broker = Read-Host "Type FQDN of rd broker server"
#getting all user ids 
$userids = Get-RDUserSession -ConnectionBroker "$broker" | Sort-Object Username
$sessions = ($userids | Select-Object UserName,UnifiedSessionId)|Out-String
Write-host "Getting all active sessions on rd broker $broker" -ForegroundColor Yellow
Write-host "$sessions" -ForegroundColor Yellow
#send message to all user ids
foreach($uid in $userids){
            $id = (($uid).UnifiedSessionID)
            $user = (($uid).UserName)
            Send-RDUserMessage -HostServer $broker -UnifiedSessionID $id -MessageTitle "$msgtitel" -MessageBody "$msg"
            Write-Host "Sending message to user: $user with titel: $msgtitel" -ForegroundColor Green
}
pause

here my script in action.

After this short introduction, see some tips to handle my ps script from github with parameters:

EXAMPLE 1 simple execution:

EXAMPLE 2 execution with parameters
.\rdmessenger.ps1 -rdbroker rds02.demo01.it-koehler.com -messagetitel “admin message” -message “message to display” -Verbose

EXAMPLE 3 execution with parameter -rdsessionhost
.\rdmessenger.ps1 -rdbroker rds02.demo01.it-koehler.com -messagetitel “admin message” -message “message to display” -rdsessionhost rds02.demo01.it-koehler.com

Features of this script:

  • checks modules required
  • imports modules required
  • waiting 10 seconds before notification is send to all users
  • see what it does with verbose command

Also have a look at my comments inside script if you want to know what it does.

If you have any further questions please leave me a message. If you like the tool click on helpful. Have fun sending messages to your users.

Print Friendly, PDF & Email
  • Was this Helpful ?
  • yes   no

One thought on “RDS/Terminalserver message/notification to all active users

Leave a Reply

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