Rename, enable credential indexing per domain\username

This commit is contained in:
paradizelost 2018-03-29 13:13:44 -05:00
parent f3f8ebbee7
commit e0bb9b9ad1

View File

@ -6,7 +6,7 @@
Path to the CSV file with the following column headers: Path to the CSV file with the following column headers:
ServerName,IPAddress,Port,LogonDomain,LogonUserID,ScreenSize,Console,RestrictedAdmin,Width,Height,Span,MultiMon,Prompt,Gateway ServerName,IPAddress,Port,LogonDomain,LogonUserID,ScreenSize,Console,RestrictedAdmin,Width,Height,Span,MultiMon,Prompt,Gateway
.NOTES .NOTES
Name: Manage-RemoteConnection.ps1 Name: Manage-RDPConnection.ps1
Author: Dan Hamik Author: Dan Hamik
Contact: Email - danhamik@gmail.com Contact: Email - danhamik@gmail.com
DateCreated: 2018-03-23 DateCreated: 2018-03-23
@ -34,46 +34,47 @@ Add-Type @"
"@ -ErrorAction SilentlyContinue "@ -ErrorAction SilentlyContinue
$headers = @("ServerName", "GroupName", "IPAddress", "Port", "LogonDomain", "LogonUserID", "ScreenSize", "Console", "Width", "Height", "Span", "MultiMon", "Gateway") $headers = @("ServerName", "GroupName", "IPAddress", "Port", "LogonDomain", "LogonUserID", "ScreenSize", "Console", "Width", "Height", "Span", "MultiMon", "Gateway")
$creds = @{}
function Global:connect-server(){ function Global:connect-server(){
param( param(
[parameter(Mandatory)][int]$ServerInfo [parameter(Mandatory)][int]$ServerInfo
) )
$myserver = $Global:RDPList[$ServerInfo] $myserver = $Global:RDPList[$ServerInfo]
write-output "HERE" $credinfo = "$($myserver.LogonDomain)\$($myserver.logonuserid)"
write-output $myserver.LogonDmain if ($creds["$credinfo"]) {
write-output $myserver.logonuserid $cred = $creds["$credinfo"]
$credinfo = "$($myserver.LogonDmain)\$($myserver.logonuserid)" } else {
write-output $credinfo $creds["$credinfo"] = Get-Credential
if (-not(get-variable cred -scope script -ErrorAction SilentlyContinue)) { $cred = $creds["$credinfo"]
$script:cred = Get-Credential
} }
<#
$process = start-process mstsc.exe -ArgumentList "/v:$($myserver.ServerName) /public" -PassThru $process = start-process mstsc.exe -ArgumentList "/v:$($myserver.ServerName) /public" -PassThru
[void][WinAP]::SetForegroundWindow($process.MainWindowHandle) [void][WinAP]::SetForegroundWindow($process.MainWindowHandle)
[void][Winap]::ShowWindow($process.MainWindowHandle, 5) [void][Winap]::ShowWindow($process.MainWindowHandle, 5)
[void][Winap]::ShowWindow($process.MainWindowHandle, 5) [void][Winap]::ShowWindow($process.MainWindowHandle, 5)
start-sleep 2 start-sleep 2
#write-output $cred.getnetworkcredential().password #write-output $cred.getnetworkcredential().password
[System.Windows.Forms.SendKeys]::SendWait("$($script:cred.username){TAB}") [System.Windows.Forms.SendKeys]::SendWait("$($cred.username){TAB}")
start-sleep .5 start-sleep .5
[System.Windows.Forms.SendKeys]::SendWait("$($script:cred.getnetworkcredential().password){enter}") [System.Windows.Forms.SendKeys]::SendWait("$($cred.getnetworkcredential().password){enter}")
#>
} }
function Show-Form() { function Show-Form() {
Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Windows.Forms
$form = New-Object Windows.Forms.Form $form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size @(200, 100) #$form.Size = New-Object Drawing.Size @(200, 100)
$form.StartPosition = "CenterScreen" $form.StartPosition = "CenterScreen"
$form.AutoSize = $true $form.AutoSize = $true
$form.AutoScroll=$true $form.AutoScroll=$false
$form.VerticalScroll.Visible=$true $form.VerticalScroll.Visible=$false
$maintable = New-Object System.Windows.Forms.TableLayoutPanel $maintable = New-Object System.Windows.Forms.TableLayoutPanel
$maintable.Dock = [System.Windows.Forms.DockStyle]::Top $maintable.Dock = [System.Windows.Forms.DockStyle]::Top
$maintable.autosize = $true $maintable.autosize = $true
$maintable.CellBorderStyle = "Inset" $maintable.CellBorderStyle = "Inset"
$maintable.VerticalScroll.Visible=$true
$maintable.AutoScroll=$true
$form.controls.add($maintable) $form.controls.add($maintable)
#$maintable.VerticalScroll.Visible=$true #$maintable.VerticalScroll.Visible=$true
$gb = @{} $gb = @{}
$gbindex=0
$gt = @{} $gt = @{}
$index=0 $index=0
foreach ($groupname in ($Global:RDPList|Select-Object -property GroupName -Unique).groupname) { foreach ($groupname in ($Global:RDPList|Select-Object -property GroupName -Unique).groupname) {
@ -91,8 +92,9 @@ function Show-Form() {
$mygb.Controls.add($mygt) $mygb.Controls.add($mygt)
$gb.add($groupname, $mygb) $gb.add($groupname, $mygb)
$gt.add($groupname, $mygt) $gt.add($groupname, $mygt)
$maintable.controls.add($mygb, 0, $index) $maintable.controls.add($mygb, $gbindex, $index)
$index++
if ($gbindex -eq 1) {$gbindex = 0; $index++}else {$gbindex++}
} }
$GroupColumn = @{} $GroupColumn = @{}
@ -116,7 +118,7 @@ function Show-Form() {
write-verbose "$($GroupRow["$groupname"]) $($GroupColumn["$groupname"])" write-verbose "$($GroupRow["$groupname"]) $($GroupColumn["$groupname"])"
write-verbose $btn.size write-verbose $btn.size
$gt["$groupname"].Controls.Add($btn,$GroupColumn["$groupname"],$GroupRow["$groupname"]) $gt["$groupname"].Controls.Add($btn,$GroupColumn["$groupname"],$GroupRow["$groupname"])
if ($GroupColumn["$groupname"] -eq 4) {$GroupColumn["$groupname"] = 0; $GroupRow["$groupname"]++} else { $GroupColumn["$groupname"]++} if ($GroupColumn["$groupname"] -eq 2) {$GroupColumn["$groupname"] = 0; $GroupRow["$groupname"]++} else { $GroupColumn["$groupname"]++}
} }
$form.width = $maintable.Width $form.width = $maintable.Width
$drc = $form.ShowDialog() $drc = $form.ShowDialog()
@ -178,9 +180,11 @@ Q: Quit
} }
$Global:CSVPath = $CSVPath $Global:CSVPath = $CSVPath
if (-not(test-path $CSVPath)) { if (-not(test-path $CSVPath)) {
$edit=$true
new-item $CSVPath new-item $CSVPath
set-content -path $CSVPath -Value "`"ServerName`",`"GroupName`",`"IPAddress`",`"Port`",`"LogonDomain`",`"LogonUserID`",`"ScreenSize`",`"Console`",`"Width`",`"Height`",`"Span`",`"MultiMon`",`"Gateway`"" set-content -path $CSVPath -Value "`"ServerName`",`"GroupName`",`"IPAddress`",`"Port`",`"LogonDomain`",`"LogonUserID`",`"ScreenSize`",`"Console`",`"Width`",`"Height`",`"Span`",`"MultiMon`",`"Gateway`""
} elseif ( (get-content $CSVPath) -eq "") { } elseif ( (get-content $CSVPath) -eq "") {
$edit=$true
set-content -path $CSVPath -Value "`"ServerName`",`"GroupName`",`"IPAddress`",`"Port`",`"LogonDomain`",`"LogonUserID`",`"ScreenSize`",`"Console`",`"Width`",`"Height`",`"Span`",`"MultiMon`",`"Gateway`"" set-content -path $CSVPath -Value "`"ServerName`",`"GroupName`",`"IPAddress`",`"Port`",`"LogonDomain`",`"LogonUserID`",`"ScreenSize`",`"Console`",`"Width`",`"Height`",`"Span`",`"MultiMon`",`"Gateway`""
} }