Skip to content

Instantly share code, notes, and snippets.

@kzu
Last active October 22, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzu/91aaea46c020abe52bb21881be88597b to your computer and use it in GitHub Desktop.
Save kzu/91aaea46c020abe52bb21881be88597b to your computer and use it in GitHub Desktop.
Cleanup-VS
# 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
}
#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