RDPManager – PowerShell Based

A quick quality of life script.

Add Favorites from the drop down of Domain Controllers, or manual entry from the textbox.
Double-click a Favorite or click on Launch to open MSTSC for the selected server.
Favorites are saved in a JSON file on your desktop.

Note: Change ‘forest.local’ to the proper forest name of your environment for polling domain controllers. If you’d like to pull in all servers from your forest / domain, you’ll need to change what objects are populated into the $ADDCs variable (I.E. Use the Get-ADComputer cmdlet).

RDPManager
RDPManager
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# PowerShell RDP Manager
# Version: 1.1
# Created: 2018-06-28
# Modified: 20-18-07-02
#=====================================================
$RDPFavs = "$env:USERPROFILE\Desktop\RDPFavs.json"
CLS

If ($host.Name -like "*ISE*"){    
    Write-Warning "Launching into a regular powershell console window"
    If ($MyInvocation.MyCommand.Path) {
        $scriptpath = $MyInvocation.MyCommand.Path -replace ' ', '` '
        Invoke-Expression "start powershell {$scriptpath}"        
    }
    break
}

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

Function Load-Favs {
  If (Test-Path -Path $RDPFavs -ErrorAction SilentlyContinue) {
    $Favs = Get-Content -Raw $RDPFavs | ConvertFrom-Json
    ForEach ($Fav in $Favs) {
        $list_favs.Items.Add($Fav)
    }
  } Else {
    $Favs = $null
  }
}

Function Save-Favs {
    $list_favs.Items | ConvertTo-Json | Out-File $RDPFavs
}

Function Start-RDP ($computername){    
    Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$computername"
}

Function Get-AllDCs {
    $ADDCs = (Get-ADForest 'forest.local' -ErrorAction SilentlyContinue -ErrorVariable errForest ).domains | ForEach {Get-ADDomain -Identity $_ -ErrorAction SilentlyContinue } | ForEach {Get-ADDomainController -Server $_.DNSRoot -Filter * -ErrorAction SilentlyContinue } | select HostName | Sort-Object
    If ($errForest) {
        $cmb_allDCs.items.Add("Error Loading DCs - $($errForest.message)")
    } Else {
        ForEach ($DC in $ADDCs) {
            $cmb_allDCs.items.Add( $dc.hostname )
        }
        $cmb_allDCs.Sorted = $true
    }
}

#region begin GUI{

$rdpManager                      = New-Object system.Windows.Forms.Form
$rdpManager.ClientSize           = '600,355'
$rdpManager.text                 = "RDP Manager"
$rdpManager.TopMost              = $false
#$rdpManager.icon                 = '\\path\to\icon.ico'

$Label1                          = New-Object system.Windows.Forms.Label
$Label1.text                     = "Favorites"
$Label1.AutoSize                 = $true
$Label1.width                    = 25
$Label1.height                   = 10
$Label1.location                 = New-Object System.Drawing.Point(12,15)
$Label1.Font                     = 'Microsoft Sans Serif,10'

$cmb_allDCs                      = New-Object system.Windows.Forms.ComboBox
$cmb_allDCs.text                 = "Select"
$cmb_allDCs.width                = 278
$cmb_allDCs.height               = 20
$cmb_allDCs.location             = New-Object System.Drawing.Point(302,42)
$cmb_allDCs.Font                 = 'Microsoft Sans Serif,10'
$cmb_allDCs.AutoSize             = $true

$Label2                          = New-Object system.Windows.Forms.Label
$Label2.text                     = "All Domain Controllers"
$Label2.AutoSize                 = $true
$Label2.width                    = 25
$Label2.height                   = 10
$Label2.location                 = New-Object System.Drawing.Point(302,18)
$Label2.Font                     = 'Microsoft Sans Serif,10'

$btn_AddToFavs                   = New-Object system.Windows.Forms.Button
$btn_AddToFavs.text              = "Add To Favs"
$btn_AddToFavs.width             = 184
$btn_AddToFavs.height            = 27
$btn_AddToFavs.location          = New-Object System.Drawing.Point(354,133)
$btn_AddToFavs.Font              = 'Microsoft Sans Serif,10'

$btn_removeFav                   = New-Object system.Windows.Forms.Button
$btn_removeFav.text              = "Remove Selected From Favs"
$btn_removeFav.width             = 195
$btn_removeFav.height            = 30
$btn_removeFav.location          = New-Object System.Drawing.Point(44,310)
$btn_removeFav.Font              = 'Microsoft Sans Serif,10'

$txt_addFav                      = New-Object system.Windows.Forms.TextBox
$txt_addFav.multiline            = $false
$txt_addFav.width                = 279
$txt_addFav.height               = 20
$txt_addFav.location             = New-Object System.Drawing.Point(302,74)
$txt_addFav.Font                 = 'Microsoft Sans Serif,10'

$Label3                          = New-Object system.Windows.Forms.Label
$Label3.text                     = "Select from above, or enter hostname manually"
$Label3.AutoSize                 = $true
$Label3.width                    = 25
$Label3.height                   = 10
$Label3.location                 = New-Object System.Drawing.Point(302,109)
$Label3.Font                     = 'Microsoft Sans Serif,10'

$btn_launch                      = New-Object system.Windows.Forms.Button
$btn_launch.text                 = "Launch RDP for Selected Fav"
$btn_launch.width                = 199
$btn_launch.height               = 30
$btn_launch.location             = New-Object System.Drawing.Point(337,310)
$btn_launch.Font                 = 'Microsoft Sans Serif,10'

$list_favs                        = New-Object system.Windows.Forms.ListBox
$list_favs.text                   = "Select"
$list_favs.width                  = 275
$list_favs.height                 = 249
$list_favs.location               = New-Object System.Drawing.Point(12,42)

$rdpManager.controls.AddRange(@($Label1,$cmb_allDCs,$Label2,$btn_AddToFavs,$btn_removeFav,$txt_addFav,$Label3,$btn_launch,$list_favs))

#region gui events {
$btn_launch.Add_Click({
    Start-RDP($list_favs.SelectedItem)
    Write-Host "Launching RDP for $($list_favs.SelectedItem)"
})
$btn_removeFav.Add_Click({    
    $list_favs.Items.RemoveAt($list_favs.SelectedIndex)
    Save-Favs
})
$btn_AddToFavs.Add_Click({    
    If ($txt_addFav.Text.Length -gt 0){
        $list_favs.Items.Add($txt_addFav.Text)
        Save-Favs
        $txt_addFav.Text = ""
    } Else {
        $list_favs.Items.Add($cmb_allDCs.SelectedItem)
        Save-Favs
    }
})

$txt_addFav.Add_KeyUp({
    if ($_.KeyCode -eq "Enter") {
        If ($txt_addFav.Text.Length -gt 0){
            $list_favs.Items.Add($txt_addFav.Text)
            Save-Favs
            $txt_addFav.Text = ""
        }
    }
})

$rdpManager.Add_Load({ Load-Favs; Get-AllDCs })
$list_favs.Add_DoubleClick({
    Start-RDP($list_favs.SelectedItem)
    Write-Host "Launching RDP for $($list_favs.SelectedItem)"
})
#endregion events }

#endregion GUI }

[void]$rdpManager.ShowDialog()