Created
May 15, 2021 00:45
-
-
Save DCCoder90/dc05ff304becd7e98d36950ebfc4cb1f to your computer and use it in GitHub Desktop.
Powershell scrip to iterate through a directory containing git repos and perform a specified action. https://stackoverflow.com/questions/66249041/iterate-thru-all-folders-at-the-current-path-where-the-script-resides
This file contains hidden or 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 global:Start-ForAllRepos | |
{ | |
[CmdletBinding()] | |
param ( | |
[Parameter(Position=0)] | |
[string] | |
$Cmd = 'git status', | |
[Parameter(Position=1)] | |
[string[]] | |
$RepoRoot = @( | |
'd:\git' | |
), | |
[switch] | |
$Wait | |
) | |
$currentLocation = Get-Location | |
foreach ($root in $RepoRoot) | |
{ | |
Set-Location $root | |
Get-ChildItem -Directory -Exclude '.vscode' | | |
Select-Object -ExpandProperty FullName | | |
ForEach-Object { | |
# check if this is a git repo | |
if (-not (Test-Path (Join-Path $_ '.git'))) | |
{ | |
#"Not a git repo $($_)" | |
continue; | |
} | |
"-"*72 | |
$_ | |
$Cmd | |
"-"*72 | |
Set-Location $_ | |
cmd.exe /c $Cmd | |
# wait when requested | |
if ($Wait) { | |
$null = Read-Host -Prompt "Press enter to continue..." | |
} | |
} | |
Set-Location $root | |
} | |
Set-Location $currentLocation | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment