Skip to content

Latest commit

 

History

History
83 lines (68 loc) · 2.05 KB

File metadata and controls

83 lines (68 loc) · 2.05 KB

The 'build-repos.ps1' Script

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

Related Links

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 04/19/2026 17:56:56)