Functions/Start-RDP.ps1


function Start-RDP {
    [CmdletBinding()]
    param (
        [Parameter()] [string] $ComputerName,
        [Parameter()] [int] $Port = 3389,
        [Parameter()] [ValidateSet("1080", "1440", "Fullscreen")] [string] $Resolution = "1440",
        [Parameter()] [ValidateSet("AudioDontPlay", "AudioRemote", "AudioRedirect")] [string] $AudioMode = "AudioRemote",
        [Parameter()] [switch] $NoCredSSP
    )



    $WindowSizes = [PSCustomObject]@{
        1080       = @"
screen mode id:i:1
desktopwidth:i:1917
desktopheight:i:1006

"@


        1440       = @"
screen mode id:i:1
desktopwidth:i:2558
desktopheight:i:1366

"@


        Fullscreen = @"
screen mode id:i:2

"@


    }

    $AudioModes = [PSCustomObject]@{
        AudioDontPlay = @"
audiomode:i:2

"@

        AudioRemote   = @"
audiomode:i:1

"@

        AudioRedirect = @"
audiomode:i:0

"@

    }


    if ($NoCredSSP) {
        $CredSSPContent = @"
enablecredsspsupport:i:0

"@

    } else {
        $CredSSPContent = ""
    }


    if ($ComputerName) {
        $ContentFullAddress = @"
full address:s:$($ComputerName):$($Port)

"@

    } else {
        $ContentFullAddress = @"
full address:s:

"@

    }


    $DefaultRdpFileContent = @"
use multimon:i:0
session bpp:i:32
winposstr:s:0, 3, 0, 0, 800, 600
compression:i:1
keyboardhook:i:1
audiocapturemode:i:0
videoplaybackmode:i:1
connection type:i:7
networkautodetect:i:1
bandwidthautodetect:i:1
displayconnectionbar:i:1
enableworkspacereconnect:i:0
disable wallpaper:i:0
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1
redirectprinters:i:0
redirectcomports:i:0
redirectsmartcards:i:1
redirectclipboard:i:1
redirectposdevices:i:0
drivestoredirect:s:
autoreconnection enabled:i:1
authentication level:i:2
prompt for credentials:i:0
negotiate security layer:i:1
remoteapplicationmode:i:0
alternate shell:s:
shell working directory:s:
gatewayhostname:s:
gatewayusagemethod:i:4
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:0
promptcredentialonce:i:0
gatewaybrokeringtype:i:0
use redirection server name:i:0
rdgiskdcproxy:i:0
kdcproxyname:s:

"@








    $RdpFileContent = $DefaultRdpFileContent + $ContentFullAddress + $WindowSizes.$Resolution + $AudioModes.$AudioMode + $CredSSPContent
    if ($ComputerName) {
        $Outfile = "$($env:TEMP)\$($Computername).rdp"
    } else {
        $Outfile = "$($env:TEMP)\RDP.rdp"
    }

    $RdpFileContent | Out-File $Outfile

    Start-Process $Outfile

    Get-Content $Outfile
    # Remove-Item $Outfile -Force

}