2024-01-25 13:37:12 +01:00
|
|
|
Script: *check-repos.ps1*
|
|
|
|
========================
|
2024-01-03 12:11:22 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
This PowerShell script verifies the data integrity of all Git repositories in a folder.
|
2024-01-03 12:11:22 +01:00
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
```powershell
|
|
|
|
PS> ./check-repos.ps1 [[-parentDir] <String>] [<CommonParameters>]
|
|
|
|
|
|
|
|
-parentDir <String>
|
2024-05-19 10:25:56 +02:00
|
|
|
Specifies the file path to the parent folder
|
2024-01-03 12:11:22 +01:00
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value "$PWD"
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
```powershell
|
2024-05-19 10:25:56 +02:00
|
|
|
PS> ./check-repos.ps1 C:\Repos
|
|
|
|
⏳ Checking parent folder 📂C:\Repos... 16 subfolders
|
|
|
|
⏳ Checking 📂rust repository (1/16)...
|
|
|
|
...
|
|
|
|
✔️ Checked all 16 Git repos in 📂C:\Repos in 356s.
|
2024-01-03 12:11:22 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Notes
|
|
|
|
-----
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
|
|
|
Related Links
|
|
|
|
-------------
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
|
|
|
Script Content
|
|
|
|
--------------
|
|
|
|
```powershell
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Checks Git repositories
|
|
|
|
.DESCRIPTION
|
2024-05-19 10:25:56 +02:00
|
|
|
This PowerShell script verifies the data integrity of all Git repositories in a folder.
|
2024-01-03 12:11:22 +01:00
|
|
|
.PARAMETER parentDir
|
2024-05-19 10:25:56 +02:00
|
|
|
Specifies the file path to the parent folder
|
2024-01-03 12:11:22 +01:00
|
|
|
.EXAMPLE
|
2024-05-19 10:25:56 +02:00
|
|
|
PS> ./check-repos.ps1 C:\Repos
|
|
|
|
⏳ Checking parent folder 📂C:\Repos... 16 subfolders
|
|
|
|
⏳ Checking 📂rust repository (1/16)...
|
|
|
|
...
|
|
|
|
✔️ Checked all 16 Git repos in 📂C:\Repos in 356s.
|
2024-01-03 12:11:22 +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
|
2024-05-19 10:25:56 +02:00
|
|
|
Write-Host "⏳ Checking parent folder 📂$parentDir... " -noNewline
|
2024-01-03 12:11:22 +01:00
|
|
|
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access folder: $parentDir" }
|
|
|
|
$folders = (Get-ChildItem "$parentDir" -attributes Directory)
|
|
|
|
$numFolders = $folders.Count
|
2024-05-19 10:25:56 +02:00
|
|
|
"$numFolders subfolders"
|
2024-01-03 12:11:22 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
[int]$step = 1
|
2024-01-03 12:11:22 +01:00
|
|
|
foreach ($folder in $folders) {
|
2024-05-19 10:25:56 +02:00
|
|
|
"`n⏳ Checking 📂$folder repository ($step/$numFolders)..."
|
2024-01-03 12:11:22 +01:00
|
|
|
& "$PSScriptRoot/check-repo.ps1" "$folder"
|
2024-05-19 10:25:56 +02:00
|
|
|
$step++
|
2024-01-03 12:11:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
2024-05-19 10:25:56 +02:00
|
|
|
"✔️ Checked all $numFolders Git repos in 📂$parentDir in $($elapsed)s."
|
2024-01-03 12:11:22 +01:00
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of check-repos.ps1 as of 05/19/2024 10:25:18)*
|