Last active
June 1, 2024 03:12
-
-
Save houstonhaynes/be404281f9e1dfe44bdf307efff7eab1 to your computer and use it in GitHub Desktop.
A script to cycle through each "Meadow." folder and run 'git pull' then output results to a local log file.
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
# Define the root directory where you want to start the search | |
$rootDirectory = "D:\repos" | |
# Create a unique log file with a datetime stamp | |
$logFileName = "Meadow_pull_log_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt" | |
$logFilePath = Join-Path -Path $rootDirectory -ChildPath $logFileName | |
# Get immediate child folders (one level down) | |
$childFolders = Get-ChildItem -Path $rootDirectory -Directory | |
# Store the current location (parent folder) | |
$currentLocation = Get-Location | |
foreach ($folder in $childFolders) { | |
$folderName = $folder.Name | |
if ($folderName -like "*Meadow.*") { | |
# Change to the folder | |
Set-Location $folder.FullName | |
# Run "git pull" and capture the output | |
$gitOutput = git pull 2>&1 | |
# Split the output into lines | |
$gitOutputLines = $gitOutput -split "`r`n" | |
# Append the folder name and Git output to the log file | |
"$folderName`r`n$(($gitOutputLines | % { "$_`r`n" }) -join '')" | Out-File -Append -FilePath $logFilePath | |
# Display the folder name and Git output in the console | |
Write-Host "Folder: $folderName" | |
Write-Host $gitOutput | |
# Return to the parent folder | |
Set-Location $currentLocation | |
} | |
} | |
# Display the path to the log file | |
Write-Host "Git output saved to: $logFilePath" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment