Skip to content

Instantly share code, notes, and snippets.

@trstringer
Created June 26, 2015 15:39
Show Gist options
  • Save trstringer/51dd1ecb1847daeab324 to your computer and use it in GitHub Desktop.
Save trstringer/51dd1ecb1847daeab324 to your computer and use it in GitHub Desktop.
Searches all file system drives for all Git repositories, and then lists them out
foreach ($DriveRoot in (Get-PSDrive | Where-Object {$_.Provider -like "*FileSystem"} | Select-Object -ExpandProperty Root)) {
Set-Location $DriveRoot
$FoundRepos =
Get-ChildItem ".git" -Directory -Force -Recurse -ErrorAction SilentlyContinue |
Select-Object @{Name = "Repository"; Expression = { $_.FullName.Substring(0, $_.FullName.IndexOf("\.git")) }}
if ($FoundRepos -eq $null) {
$RepoCount = 0
}
elseif ($FoundRepos -ne $null -and $FoundRepos.Count -eq $null) {
$RepoCount = 1
}
else {
$RepoCount = $FoundRepos.Count
}
"Found $RepoCount repository(ies) on $DriveRoot"
if ($RepoCount -gt 0) {
"========================"
$FoundRepos |
Select-Object -ExpandProperty Repository
}
"`r`n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment