PowerShell/scripts/check-repos.ps1

46 lines
1.3 KiB
PowerShell
Raw Normal View History

2024-10-01 15:11:03 +02:00
<#
2023-12-31 15:47:19 +01:00
.SYNOPSIS
Checks Git repositories
.DESCRIPTION
2024-05-02 15:36:41 +02:00
This PowerShell script verifies the data integrity of all Git repositories in a folder.
2023-12-31 15:47:19 +01:00
.PARAMETER parentDir
Specifies the file path to the parent folder
2023-12-31 15:47:19 +01:00
.EXAMPLE
PS> ./check-repos.ps1 C:\Repos
2024-05-02 15:36:41 +02:00
Checking parent folder 📂C:\Repos... 16 subfolders
Checking 📂rust repository (1/16)...
...
2024-10-01 13:37:53 +02:00
Checked all 16 Git repos in 📂C:\Repos in 356s.
2023-12-31 15:47:19 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$parentDir = "$PWD")
try {
$stopWatch = [system.diagnostics.stopwatch]::startNew()
$parentDirName = (Get-Item "$parentDir").Name
Write-Host "⏳ Checking parent folder 📂$parentDir... " -noNewline
2023-12-31 15:47:19 +01:00
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access folder: $parentDir" }
$folders = (Get-ChildItem "$parentDir" -attributes Directory)
$numFolders = $folders.Count
"$numFolders subfolders"
2023-12-31 15:47:19 +01:00
2024-05-02 15:36:41 +02:00
[int]$step = 1
2023-12-31 15:47:19 +01:00
foreach ($folder in $folders) {
2024-05-02 15:36:41 +02:00
"`n⏳ Checking 📂$folder repository ($step/$numFolders)..."
2023-12-31 15:47:19 +01:00
& "$PSScriptRoot/check-repo.ps1" "$folder"
$step++
2023-12-31 15:47:19 +01:00
}
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
2024-09-24 21:28:31 +02:00
"✅ Checked all $numFolders Git repos in 📂$parentDir in $($elapsed)s."
2023-12-31 15:47:19 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}