Skip to content

Instantly share code, notes, and snippets.

@RauchF
Created June 5, 2020 10:52
Show Gist options
  • Save RauchF/00d7dfee741f1516f312fd28bc075c87 to your computer and use it in GitHub Desktop.
Save RauchF/00d7dfee741f1516f312fd28bc075c87 to your computer and use it in GitHub Desktop.
Quickly switch between versions of software by using a symlink in Windows
#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