Created
March 27, 2025 20:47
-
-
Save awakecoding/4f75c72ec3149011751d09aa6e5c3e3e 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
$Appx = Get-AppxPackage -AllUsers | Where-Object { | |
$_.PackageFamilyName -eq "MicrosoftCorporationII.Windows365_8wekyb3d8bbwe" | |
} | Select-Object -First 1 | |
if (-not $Appx) { | |
Write-Error "Windows365 MSRDC package not found." | |
return | |
} | |
$Source = Join-Path $Appx.InstallLocation "msrdc" | |
$exe = Join-Path $Source "msrdc.exe" | |
$Version = (Get-ItemProperty $exe).VersionInfo.ProductVersion | |
$LocalApps = Join-Path $Env:LocalAppData "Apps" | |
$LatestPath = Join-Path $LocalApps "MSRDC" | |
$VersionPath = Join-Path $LocalApps "MSRDC.$Version" | |
# Copy only if the versioned path doesn't exist | |
if (-Not (Test-Path $VersionPath)) { | |
Write-Output "Copying MSRDC to $VersionPath" | |
Copy-Item $Source $VersionPath -Recurse | |
} | |
# Check if MSRDC junction already exists and points to correct location | |
$shouldCreateJunction = $true | |
if (Test-Path $LatestPath) { | |
$item = Get-Item $LatestPath -Force | |
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) { | |
$resolved = [IO.Path]::GetFullPath($item.Target) | |
$expected = [IO.Path]::GetFullPath($VersionPath) | |
if ($resolved -ieq $expected) { | |
Write-Output "Junction already exists and points to correct version." | |
$shouldCreateJunction = $false | |
} else { | |
Write-Output "Removing existing junction: $LatestPath" | |
Remove-Item $LatestPath -Force | |
} | |
} else { | |
Write-Error "$LatestPath exists and is not a junction. Please remove it manually." | |
return | |
} | |
} | |
# Create junction only if needed | |
if ($shouldCreateJunction) { | |
Write-Output "Creating junction: $LatestPath -> $VersionPath" | |
cmd.exe /c mklink /J `"$LatestPath`" `"$VersionPath`" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment