Send-xRDS_User_Message.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function Send-xRDS_User_Message {

<#
    .DESCRIPTION
    Sends message to selected users from a sessions list.
  
    .PARAMETER Broker
    -ConnectionBroker - FQDN of RDS ConnectionBroker.
 
    .PARAMETER Message
    -Message - Message text to display for selected 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 a users on selected RDS Host servers:
    Send-xRDS_User_Message -ConnectionBroker ardscbl01.adatum.labnet -Message "Please call support for assistance."
     
    .LINK
    https://www.securemfa.com/downloads/mfa-rds-otp
#>



    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)][string]$ConnectionBroker,    
        [Parameter(Mandatory=$true)][string]$Message,
        [Int]$DisplayMessageSeconds = 300,
        [PSCredential]$Credential
    )      

    $SelectedUsers = Get-xRDS_UsersList -ConnectionBroker $ConnectionBroker -Credential $Credential

    Try {

    If ($SelectedUsers.UserName.Count -le 0) {Write-Host "No users have been selected." -ForegroundColor Cyan }
    else { Write-Host "Message: $Message Will display $DisplayMessageSeconds seconds to folowing users:" -ForegroundColor Cyan ; $SelectedUsers | foreach {Write-Host "Username: $($_.UserName) SID: $($_.SID) Collection: $($_.Collection) HOST: $($_.Host) " -ForegroundColor Cyan ; start-process msg "$($_.SID) /SERVER:$($_.Host) /TIME:$($DisplayMessageSeconds) $($Message)" -WindowStyle Hidden}}

    } Catch {Write-host $_.Exception.message -ForegroundColor Red}
}