Created
February 25, 2015 08:56
-
-
Save aplocher/31d9888a0cb6e634fafd to your computer and use it in GitHub Desktop.
Powershell script to list or remove Visual Studio hives
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
param ( | |
[string]$fullName = "", # Example: "12.0Exp" is VS v12.0 (2013) hive name "Exp" | |
[switch]$listHives = $false, | |
[switch]$force = $false | |
) | |
$vsAppDataRoot = Join-Path $env:APPDATA "Microsoft\VisualStudio" | |
$vsRegKeyRoot = "hkcu:\Software\Microsoft\VisualStudio" | |
if (-not $fullName -and -not $listHives) { | |
Write-Warning 'Must provide a hive name with the -fullName switch. To get a list of hive names, run with -listHives switch.' | |
exit | |
} | |
if ($listHives) { | |
Join-Path $env:APPDATA "Microsoft\VisualStudio" | Get-ChildItem | Select-Object -Property ` | |
@{ Name="Full Name"; Expression={$_.Name}}, | |
@{ Name="VS Version"; Expression={ | |
switch($_.Name | Select-String -pattern "^[0-9]+\.[0-9]" -AllMatches | %{$_.Matches[0].Value }) { | |
"14.0"{"VS 2015"} | |
"12.0"{"VS 2013"} | |
"11.0"{"VS 2012"} | |
"10.0"{"VS 2010"} | |
"9.0"{"VS 2008"} | |
"8.0"{"VS 2005"} | |
"7.1"{"VS 2003"} | |
"7.0"{"VS 2002 (.NET)"} | |
default {"(unknown)"} | |
} | |
} | |
}, | |
@{ Name="Hive Name"; Expression={ | |
$hiveName = $_.Name | Select-string -pattern "^[0-9]+\.[0-9]([A-Za-z0-9]+)$" -AllMatches | %{$_.Matches[0].Groups[1].Value } | |
if (-not $hiveName) { | |
"(default or unknown)" | |
} else { | |
$hiveName | |
} | |
} | |
} | |
} else { | |
if (-not $fullName) { | |
Write-Error "Invalid parameters" | |
exit | |
} | |
$regKey = Join-Path $vsRegKeyRoot $fullName | |
$regConfigKey = Join-Path $vsRegKeyRoot "$($fullName)_Config" | |
$folder = Join-Path $vsAppDataRoot $fullName | |
if (-not ($vsAppDataRoot | Get-ChildItem | Where name -eq $fullName)) { | |
Write-Warning "Folder doesn't seem to exist: $($folder)" | |
if (-not $force) { | |
Write-Warning "Use -force switch to attempt cleanup anyway" | |
exit | |
} else { | |
Write-Host | |
} | |
} | |
Write-Host "Removing registry key $($regKey)" | |
if (Test-Path $regKey) { | |
Remove-Item -path $regKey -Recurse -Force | |
Write-Host "Done" | |
} else { | |
Write-Warning "path not found" | |
} | |
Write-Host | |
Write-Host "Removing registry key $($regConfigKey)" | |
if (Test-Path $regConfigKey) { | |
Remove-Item -path $regConfigKey -Recurse -Force | |
Write-Host "Done" | |
} else { | |
Write-Warning "path not found" | |
} | |
Write-Host | |
Write-Host "Removing folder $($folder)" | |
if (Test-Path $folder) { | |
Remove-Item -path $folder -Recurse -Force | |
Write-Host "Done" | |
} else { | |
Write-Warning "path not found" | |
} | |
Write-Host | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment