Skip to content

Instantly share code, notes, and snippets.

@restuu
Created November 17, 2021 07:59
Show Gist options
  • Save restuu/7945977ad0d78507d529e5e705618fc5 to your computer and use it in GitHub Desktop.
Save restuu/7945977ad0d78507d529e5e705618fc5 to your computer and use it in GitHub Desktop.
Powershell loop directories and set git config
$current_directory=Get-Location
Write-Host "Current directory: $current_directory"
Get-ChildItem | ForEach-Object -Process {
$is_folder = Test-Path -Path $_ -PathType Container
if (!$is_folder) {
# skip to next loop
return
}
# Write-Host "Inside directory Name: $_ is folder: $is_folder"
# change directory
Set-Location $_
# check if is git directory
$git_dir = ".git"
$is_git = Test-Path -Path $_\$git_dir -IsValid
# Write-Host "Inside directory Name: $_ is git: $is_git"
if ($is_git) {
# change any git config here
git config user.email "<user email>"
}
}
# return to initial dir
Set-Location $current_directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment