-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-GDShowSizeByYear.ps1
More file actions
73 lines (60 loc) · 1.74 KB
/
Copy pathGet-GDShowSizeByYear.ps1
File metadata and controls
73 lines (60 loc) · 1.74 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Get-GDShowSizeByYear
<#
.SYNOPSIS
Reports GD Archive size by year
.DESCRIPTION
Gets the on-disk size of all the shows in the GD Archive,
then reports those sizes by year
.INPUTS
none
.OUTPUTS
System.String
.NOTES
1. This assumes all files in the archive ($GDBase) are of the format:
gdyy-mm-dd-...
The regular expression in the middle of the script parses each show folder name to pull out
the year from the show name (ie the folder name)
2. All folders in $GDBase are assumed to be in that format, but if the regex match fails, it means
that for some reason, the script has found a badly named folder.
.EXAMPLE
Left as an exercises for the user
#>
Function Get-GDShowSizeByYear {
# Say Hello
"+---------------------------------+"
"! Get-GDShowByYear.ps1 v 1.0.0 !"
"! Report Show size by year !"
"+---------------------------------+"
""
# Set and report base file location
$GDBase = 'M:\gd'
"GDBase: [$GDBase]"
# Get GD folders from base
$Shows = Get-ChildItem -Path $GDBase -Directory
# Create Hash Table of size by year
$SBYHT = @{}
# Iterate
Foreach ($Show in $Shows) {
$ShowName = $Show.Name
$Check = $ShowName -Match '^gd([6-9][0-9])'
if (-Not $Check) {
"$($Show.Name) is broken - continuing"
continue
}
$Year = $Matches[1] # get the year from the parsed regex
$Size = (Get-ChildItem $Show -Rec |
Measure-Object -Sum -Property Length).Sum
# Update year size
$SBYHT[$Year] += $Size
}
# Now report
"Year GB"
$SUM = 0
$SBYHT.GetEnumerator() |
Sort-Object -Property Name |
foreach-object {
"{0,4:N2} {1,10:N2}" -f $_.Name,([int64]$_.value/1gb)
$sum += ([int64]$_.value/1gb)
}
"Total is: {0,5:N3} GB" -f $sum
} # end of function