Created
June 5, 2020 10:52
-
-
Save RauchF/00d7dfee741f1516f312fd28bc075c87 to your computer and use it in GitHub Desktop.
Quickly switch between versions of software by using a symlink in Windows
This file contains 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
#Requires -RunAsAdministrator | |
param($version) | |
$scriptDir = Split-Path (Get-Variable MyInvocation -Scope Script).Value.MyCommand.Path | |
Push-Location $scriptDir | |
$available = Get-ChildItem -Directory -Exclude "active" | |
$active = if (Test-Path "active") {Get-Item -Path "active"} else {$null} | |
if ($null -eq $version) { | |
Write-Output "No target version given. Available versions are:" | |
$available | ForEach-Object { | |
if ($active.Target -eq $_) { | |
Write-Host "* " -NoNewline | |
} | |
Write-Output $_.Name | |
} | |
return | |
} | |
if ($available.Name -notcontains $version) { | |
Write-Error "The requested version is not available." | |
return | |
} | |
Write-Debug "Setting new symlink" | |
$link = New-Item -ItemType SymbolicLink -Path "active" -Target $version -Force | |
Write-Output $link.Target | |
Pop-Location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment