You could try this.
Use: Get-FileSize "C:\folder1","C:\folder2","C:\folder3\folder1"
Output:
Name Value
---- -----
Total 1456.00
C:\folder1 100.00
C:\folder2 123.00
C:\folder3\folder1 1233.00
Doesn’t throw in MB
because of the calculations that SUM does…
Function Get-FileSize([string[]]$Array) {
$Output = @{}
Foreach($String in $Array){
$FolderInfo = Get-ChildItem -Recurse $String
$totalSize = "{0:N2}" -f (($FolderInfo | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB)
$Output.add($String, $totalSize)
}
$Output.add("Total", "{0:N2}" -f ($Output.Values | Measure-Object -Sum).Sum)
$Output
}
1
solved Calculate folder size for multiple folders [closed]