Created
November 17, 2021 07:59
-
-
Save restuu/7945977ad0d78507d529e5e705618fc5 to your computer and use it in GitHub Desktop.
Powershell loop directories and set git config
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
$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