Skip to content

Instantly share code, notes, and snippets.

@DovieW
Created May 19, 2025 16:17
Show Gist options
  • Select an option

  • Save DovieW/7e8161f8e2fe8717eaed9e2adeab0465 to your computer and use it in GitHub Desktop.

Select an option

Save DovieW/7e8161f8e2fe8717eaed9e2adeab0465 to your computer and use it in GitHub Desktop.

Revisions

  1. DovieW created this gist May 19, 2025.
    2 changes: 2 additions & 0 deletions multimon.cmd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    @echo off
    powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -File "%USERPROFILE%\Documents\multimon.ps1"
    36 changes: 36 additions & 0 deletions multimon.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    # 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: $_"
    }