Send-xRDS_Host_Message.ps1
function Send-xRDS_Host_Message { <# .DESCRIPTION Sends message to ALL users on HOST server. .PARAMETER Broker -ConnectionBroker - FQDN of RDS ConnectionBroker. .PARAMETER Message -Message - Message text to display for users. .PARAMETER Credential -Credential [Optional] - Query RDS Connection Broker resources under provided credentials. PARAMETER DisplayMessageSeconds -DisplayMessageSeconds [Optional] - Message display time in seconds (Default value is equivalent of 5 minutes). .EXAMPLE # Send message to all users on selected RDS Host servers: Send-xRDS_Host_Message -ConnectionBroker ardscbl01.adatum.labnet -Message "Server will shut down in 10 minutes for maintenance. Please log out from your session and log back again to be redirected into another Session Host." #> [CmdletBinding()] Param( [Parameter(Mandatory=$true)][string]$ConnectionBroker, [Parameter(Mandatory=$true)][string]$Message, [Int]$DisplayMessageSeconds = 300, [PSCredential]$Credential ) $Collection = Get-xRDS_CollectionsList -ConnectionBroker $ConnectionBroker -Credential $Credential Try { $ActiveManagementServer = (Invoke-WmiMethod -ComputerName $ConnectionBroker -Class "Win32_RDMSEnvironment" -Namespace "root\CIMV2\rdms" -Name "GetActiveServer").ServerName $SelectedServers = Get-WmiObject -ComputerName $ActiveManagementServer -Credential $Credential -Query "SELECT ServerName,LoadIndicator,NumberOfSessions,NumPendRedir,ServerWeight,SingleSessionMode FROM Win32_SessionDirectoryServer" | select ` @{Label="Host";Expression={$_.ServerName}}, @{Label="Collections";Expression={$Collection[$_.ServerName]}},@{Label="Sessions";Expression={$_.NumberOfSessions}}, ` @{Label="LoadIndicator";Expression={$_.LoadIndicator}},@{Label="ServerWeight";Expression={$_.ServerWeight}},` @{Label="NumPendRedir";Expression={$_.NumPendRedir}},@{Label="SingleSessionMode";Expression={$_.SingleSessionMode}} | sort Host | Out-GridView -PassThru -Title "Host Message (Select Servers)" If ($SelectedServers.Host.Count -le 0) {Write-Host "No hosts have been selected." -ForegroundColor Cyan } else { Write-Host "Message: $Message Will display $DisplayMessageSeconds seconds on folowing servers:" -ForegroundColor Cyan ; $SelectedServers.Host | foreach {Write-Host "$_" -ForegroundColor Cyan ; start-process msg "* /SERVER:$_ /TIME:$DisplayMessageSeconds $Message" -WindowStyle Hidden}} } Catch {Write-host $_.Exception.message -ForegroundColor Red} } |