Invoke-xRDS_ShadowUser.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
function Invoke-xRDS_ShadowUser {

<#
    .DESCRIPTION
    Shadows selected RDS user from a sessions list.
  
    .PARAMETER Broker
    -ConnectionBroker - FQDN of RDS ConnectionBroker.
 
    .PARAMETER Control
    -Control - Starts RDS user shadowing session with remote control access.
 
    .PARAMETER Credential
    -Credential [Optional] - Query RDS Connection Broker resources under provided credentials.
 
    .EXAMPLE
    # Starts RDS user's shadowing session with remote control access:
    Invoke-xRDS_ShadowUser -ConnectionBroker ardscbl01.adatum.labnet -Control
#>



    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)][string]$ConnectionBroker,    
        [switch]$Control,
        [PSCredential]$Credential
    )      

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

    Try {    

    If ($SelectedUsers.UserName.Count -ne 1) {Write-Host "No users have been selected or you have selected multiple users which is not allowed." -ForegroundColor Cyan }
    else { Write-Host "Shadowing user (with remote control:$Control): $($SelectedUsers.UserName) on hosts: $($SelectedUsers.Host)" -ForegroundColor Cyan ; 
        #Shadow with control
        if($Control) {Start-Process -FilePath "$env:windir\system32\mstsc.exe" -ArgumentList "/control /shadow:$($SelectedUsers.SID) /v:$($SelectedUsers.Host)"}
        #Shadow view only
        else {Start-Process -FilePath "$env:windir\system32\mstsc.exe" -ArgumentList "/shadow:$($SelectedUsers.SID) /v:$($SelectedUsers.Host)"} }

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