<# Öffnet eine RDP-Verbindung aus einem itrdp://-Link. Wird über den Protokoll-Handler aufgerufen (siehe register-handlers.reg): powershell.exe -File launch-rdp.ps1 "itrdp://connect?host=...&port=...&user=..." Mit -Pruefen wird nur angezeigt, was gestartet würde (für Tests). #> [CmdletBinding()] param( [Parameter(Mandatory = $true, Position = 0)][AllowEmptyString()][string]$Url, [switch]$Pruefen ) $ErrorActionPreference = 'Stop' . (Join-Path $PSScriptRoot 'itconnect-common.ps1') function Get-ItcRdpBefehl { param([Parameter(Mandatory = $true)]$Ziel) $adresse = Format-ItcAdresse $Ziel if ($null -eq $Ziel.User) { return [pscustomobject]@{ Programm = 'mstsc.exe'; Argumente = ('/v:' + $adresse); RdpInhalt = $null } } # mstsc kennt keinen Benutzer-Parameter, daher eine temporäre .rdp-Datei $inhalt = "full address:s:$adresse`r`nusername:s:$($Ziel.User)`r`n" return [pscustomobject]@{ Programm = 'mstsc.exe'; Argumente = $null; RdpInhalt = $inhalt } } try { $ziel = ConvertFrom-ItcUrl -Url $Url -Schema 'itrdp' -StandardPort 3389 $befehl = Get-ItcRdpBefehl $ziel if ($Pruefen) { return $befehl } if ($null -eq $befehl.RdpInhalt) { Start-Process -FilePath $befehl.Programm -ArgumentList $befehl.Argumente } else { $datei = Join-Path $env:TEMP ('it-connect-' + [guid]::NewGuid().ToString() + '.rdp') Set-Content -LiteralPath $datei -Value $befehl.RdpInhalt -Encoding Unicode Start-Process -FilePath $befehl.Programm -ArgumentList ('"' + $datei + '"') # mstsc liest die Datei beim Start; danach wieder aufräumen Start-Sleep -Seconds 10 Remove-Item -LiteralPath $datei -ErrorAction SilentlyContinue } } catch { if ($Pruefen) { throw } Show-ItcFehler ('RDP-Verbindung konnte nicht geöffnet werden: ' + $_.Exception.Message) exit 1 }