Last active
October 22, 2018 15:20
-
-
Save kzu/91aaea46c020abe52bb21881be88597b to your computer and use it in GitHub Desktop.
Cleanup-VS
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
# Add to your profile so you can run `Cleanup-VS` from any PS prompt | |
Function Cleanup-VS | |
{ | |
$script = (Split-Path -parent $PSCommandPath) + "\vscleanup.ps1" | |
&$script | |
} |
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 | |
$instances = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -format json -prerelease | convertfrom-json | |
write-host 'Installed instances: ' | |
# Grab longest version to pad properly. | |
$editionLength = ($instances | select -expand displayName | sort { $_.length } | select -last 1).length | |
$versionLength = ($instances | select -expand catalog | select -expand productDisplayVersion | sort { $_.length } | select -last 1).length | |
$instances | % { $i = 0 } { "[$i] {0} - {1} (id {3}) at {2}" -f $_.displayName.padright($editionLength, ' '), $_.catalog.productDisplayVersion.padright($versionLength, ' '), $_.installationPath, $_.instanceId; $i++ } | |
write-host | |
$index = read-host 'Enter index of instance to cleanup: ' | |
if ($index -ne '') | |
{ | |
$instance = $instances | select -skip $index -first 1 | |
if ($instance) | |
{ | |
if (test-path $instance.installationPath) | |
{ | |
write-progress -activity "Deleting $instance.installationPath ..." | |
remove-item -force -recurse $instance.installationPath | |
} | |
$instancePath = "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\" + $instance.instanceId | |
if (test-path $instancePath) | |
{ | |
write-progress -activity "Deleting $instancePath ..." | |
remove-item -force -recurse $instancePath | |
} | |
$instancePath = "C:\PackageCache\_Instances\" + $instance.instanceId | |
if (test-path $instancePath) | |
{ | |
write-progress -activity "Deleting $instancePath ..." | |
remove-item -force -recurse $instancePath | |
} | |
$hivePath = $env:LocalAppData + "\Microsoft\VisualStudio\" + $instance.installationVersion.substring(0, 2) + ".0_" + $instance.instanceId | |
if (test-path $hivePath) | |
{ | |
write-progress -activity "Deleting $hivePath ..." | |
remove-item -force -recurse $hivePath | |
} | |
$hivePath = $env:LocalAppData + "\Microsoft\VisualStudio\" + $instance.installationVersion.substring(0, 2) + ".0_" + $instance.instanceId + "Exp" | |
if (test-path $hivePath) | |
{ | |
write-progress -activity "Deleting $hivePath ..." | |
remove-item -force -recurse $hivePath | |
} | |
write-progress -activity "Done" -completed -status "All done." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment