The 'build-repos.ps1' Script

July 15, 2026 ยท View on GitHub

This PowerShell script builds all Git repositories within a folder.

Parameters

PS> ./build-repos.ps1 [[-parentDir] <String>] [<CommonParameters>]

-parentDir <String>
    Specifies the path to the parent folder
    
    Required?                    false
    Position?                    1
    Default value                "$PWD"
    Accept pipeline input?       false
    Aliases                      
    Accept wildcard characters?  false

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Example

PS> ./build-repos.ps1 C:\MyRepos

Notes

Author: Markus Fleschutz | License: CC0

https://github.com/fleschutz/PowerShell

Script Content

<#
.SYNOPSIS
	Build Git repos
.DESCRIPTION
	This PowerShell script builds all Git repositories within a folder.
.PARAMETER parentDir
	Specifies the path to the parent folder
.EXAMPLE
	PS> ./build-repos.ps1 C:\MyRepos
.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
	"โณ Step 1 - Checking parent folder ๐Ÿ“‚$parentDirName..."
	if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access folder: $parentDir" }
	$folders = (Get-ChildItem "$parentDir" -attributes Directory)
	$numFolders = $folders.Count
	"Found $numFolders subfolders."

	foreach ($folder in $folders) {
		& "$PSScriptRoot/build-repo.ps1" "$folder"
	}
	[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
	"โœ… $numFolders Git repositories built at ๐Ÿ“‚$parentDir in $($elapsed)s."
	exit 0 # success
} catch {
	"โš ๏ธ ERROR: $($Error[0]) (at line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

(page generated by convert-ps2md.ps1 as of 07/15/2026 09:43:56)