Created
May 19, 2025 16:17
-
-
Save DovieW/7e8161f8e2fe8717eaed9e2adeab0465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -File "%USERPROFILE%\Documents\multimon.ps1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clean RDP PowerShell Script | |
try { | |
# 1. Locate every .rdp file in the current user's Downloads folder | |
$downloads = Join-Path ([Environment]::GetFolderPath('UserProfile')) 'Downloads' | |
$rdpFiles = Get-ChildItem -Path $downloads -Filter '*.rdp' -File | Sort-Object LastWriteTime -Descending | |
if (-not $rdpFiles) { | |
Write-Host "No .rdp files found in $downloads" | |
return | |
} | |
# 2. Preserve the most-recent .rdp | |
$latest = $rdpFiles[0] | |
$content = Get-Content -LiteralPath $latest.FullName -Raw | |
# 3. Remove everything else | |
$rdpFiles | Select-Object -Skip 1 | Remove-Item -Force | |
# 4a. File WITH multimon -> MULTI.rdp | |
$multiPath = Join-Path $downloads 'MULTI.rdp' | |
Set-Content -LiteralPath $multiPath -Value $content -NoNewline | |
# 4b. File WITHOUT multimon -> SINGLE.rdp | |
$singlePath = Join-Path $downloads 'SINGLE.rdp' | |
$singleContent = $content -split "`r?`n" | Where-Object { $_ -notmatch '^\s*use multimon:i:' } | |
Set-Content -LiteralPath $singlePath -Value ($singleContent -join "`r`n") -NoNewline | |
# 5. Delete the original newest file | |
Remove-Item -LiteralPath $latest.FullName -Force | |
Write-Host "Done. Created:`n $multiPath`n $singlePath" | |
} | |
catch { | |
Write-Error "Something went wrong: $_" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment