Added in warning before script. Added in feature to use hostname by default for cert name. Fixed copyright date.

This commit is contained in:
Tanner van Teeffelen 2026-05-11 12:30:51 -04:00
parent 600cec442d
commit c56835cf8c

View file

@ -23,14 +23,21 @@ if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent
Write-Host "-------------------------------------------" -ForegroundColor Blue Write-Host "-------------------------------------------" -ForegroundColor Blue
Write-Host "|Developed by Tanner Van Teeffelen |" -ForegroundColor Blue Write-Host "|Developed by Tanner Van Teeffelen |" -ForegroundColor Blue
Write-Host "|Copyright ACO Services Inc. 2021 |" -ForegroundColor Blue Write-Host "|Copyright ACO Services Inc. 2026 |" -ForegroundColor Blue
Write-Host "|Based on MIT-licensed work by IanVanLier |" -ForegroundColor Blue Write-Host "|Based on MIT-licensed work by IanVanLier |" -ForegroundColor Blue
Write-Host "-------------------------------------------`n" -ForegroundColor Blue Write-Host "-------------------------------------------`n" -ForegroundColor Blue
# 1. Configuration # 1. Get existing .rdp file.
$rdpFile $rdpFile
$certSubjectName $certSubjectName
Write-Host "Before proceeding, please ensure that the .RDP file you select has the permissions you want" -ForegroundColor Green
Write-Host "This includes redirected printers, drives, and clipboard." -Foreground Green
Write-Host "If you make a change to the .RDP file, please run this program again after making your changes.`n" -ForegroundColor Red
Write-Host "Press any key to continue.`n" -ForegroundColor Green
$HOST.UI.RawUI.ReadKey(NoEcho,IncludeKeyDown) | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer()
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$FileBrowser.Filter = "RDP Files (*.rdp)|*.rdp|All Files (*.*)|*.*" $FileBrowser.Filter = "RDP Files (*.rdp)|*.rdp|All Files (*.*)|*.*"
$FileBrowser.DefaultExt = "rdp" $FileBrowser.DefaultExt = "rdp"
@ -52,10 +59,17 @@ if ([IO.Path]::GetExtension($rdpFile) -ne ".rdp") {
exit 3 exit 3
} }
$certSubjectName = Read-Host "Please type in your desired certificate subject name (e.g. 'CompanyNameIT-RDP')" # 2. Set the certificate name.
$certSubjectName = Read-Host "Please type in your desired certificate subject name. Leave blank to use hostname"
if ([string]::IsNullOrWhiteSpace($certSubjectName)) {
$certSubjectName = $env:COMPUTERNAME
}
$certSubject = "CN=$certSubjectName" $certSubject = "CN=$certSubjectName"
# 2. Check for existing certificate
# 3. Check for existing certificate
Write-Host "Searching for existing certificate: $certSubjectName..." -ForegroundColor Cyan Write-Host "Searching for existing certificate: $certSubjectName..." -ForegroundColor Cyan
$existingCert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -eq $certSubject } | Select-Object -First 1 $existingCert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -eq $certSubject } | Select-Object -First 1
@ -109,15 +123,17 @@ if ($existingCert) {
Write-Host "New certificate created and trusted." -ForegroundColor Green Write-Host "New certificate created and trusted." -ForegroundColor Green
} }
# 3. Sign the RDP File # 4. Sign the RDP File
if (Test-Path $rdpFile) { if (Test-Path $rdpFile) {
Write-Host "Signing RDP file: $rdpFile" -ForegroundColor Cyan Write-Host "Signing RDP file: $rdpFile" -ForegroundColor Cyan
# Signing with /sha256 to match modern security standards # Signing with /sha256 to match modern security standards
rdpsign.exe /sha256 $thumbprint "$rdpFile" rdpsign.exe /sha256 $thumbprint "$rdpFile"
Write-Host "Success! RDP file is ready for use." -ForegroundColor Green Write-Host "Success! RDP file is ready for use" -ForegroundColor Green
} else { } else {
Write-Error "Target RDP file not found at $rdpFile" Write-Error "Target RDP file not found at $rdpFile"
} }
Write-Host "Press any key to exit." -ForegroundColor Green
$HOST.UI.RawUI.ReadKey(NoEcho,IncludeKeyDown) | OUT-NULL $HOST.UI.RawUI.ReadKey(NoEcho,IncludeKeyDown) | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer() $HOST.UI.RawUI.Flushinputbuffer()