Last active
May 17, 2016 14:15
-
-
Save drmohundro/47b8ec91dd81757b1e43 to your computer and use it in GitHub Desktop.
PowerShell script to open a recently used solution in Visual Studio
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
function Open-MruSolution($sln) { | |
$mruItems = "HKCU:\Software\Microsoft\VisualStudio\14.0\MRUItems" | |
$guids = Get-ChildItem $mruitems | | |
Select-Object -ExpandProperty name | | |
Foreach-Object { $_.Substring($_.LastIndexOf('\') + 1) } | |
[array]$mostRecentlyUsedSlns = $guids | | |
Foreach-Object { | |
$guid = $_ | |
Get-ChildItem "$mruItems\$guid" | | |
Select-Object -ExpandProperty Property | | |
Foreach-Object { | |
$value = Get-ItemPropertyValue "$mruItems\$guid\Items" -Name $_ | |
if ($value.Contains('.sln')) { | |
$value.Substring(0, $value.IndexOf('|')) | |
} | |
} | |
} | |
if ([string]::IsNullOrWhitespace($sln)) { | |
Write-Host "Recently Used Solutions:`n" | |
for ($i = 0; $i -lt $mostRecentlyUsedSlns.Count; $i++) { | |
Write-Host "$($i + 1): $($mostRecentlyUsedSlns[$i])" | |
} | |
$toOpen = Read-Host "`nChoose # to open" | |
if ($toOpen -gt 0 -and $toOpen -le $mostRecentlyUsedSlns.Count) { | |
Write-Host "Starting $($mostRecentlyUsedSlns[$toOpen - 1])..." | |
& $mostRecentlyUsedSlns[$toOpen - 1] | |
} | |
} | |
else { | |
foreach ($mru in $mostRecentlyUsedSlns) { | |
if ($mru -like "*$sln*") { | |
Write-Host "Starting $mru..." | |
& $mru | |
break | |
} | |
} | |
} | |
} | |
Set-Alias o Open-MruSolution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update to use PowerShell v5 registry function
Get-ItemPropertyValue
.