forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-GitSize.ps1
More file actions
44 lines (39 loc) · 1.54 KB
/
Get-GitSize.ps1
File metadata and controls
44 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Function Get-GitSize {
[cmdletbinding()]
[Outputtype("gitSize")]
Param (
[Parameter(Position = 0, ValueFromPipeline, ValueFromPipelinebyPropertyName)]
[alias("pspath")]
[ValidateScript({Test-Path $_})]
[string]$Path = "."
)
Begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN] Starting $($myinvocation.mycommand)"
} #begin
Process {
$full = Convert-Path -Path $Path
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Processing path $full"
$git = Join-Path -Path $full -childpath ".git"
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Testing $git"
if (Test-Path -path $git) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Measuring $git"
#get the total size of all files in the .git folder
$stat = Get-ChildItem -path $git -Recurse -File | Measure-Object -Property length -sum
[PSCustomObject]@{
PSTypeName = "gitSize"
Name = (Split-Path -path $full -leaf)
Path = $full
Files = $stat.count
Size = $stat.sum
Date = (Get-Date)
Computername = [System.Environment]::MachineName
} #customobject
} #if test-path
else {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Did not find $git"
}
} #process
End {
Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)"
} #end
}