Adding the file sizes of Get-ChildItem listing
Use the Measure-Object
cmdlet:
$files = Get-ChildItem -Recurse -Include *jpg,*bmp,*png \\server01\folder$totalSize = ($files | Measure-Object -Sum Length).Sum
To get the size in GB divide the value by 1GB
:
$totalSize = ($files | Measure-Object -Sum Length).Sum / 1GB
You could do this as a one liner with something like this.
Get-Childitem -path "C:\Program Files\Internet Explorer" | Select-Object Name, @{Name="KBytes";Expression={ "{0:N0}" -f ($_.Length / 1KB) }}Name KBytes---- ------en-US 0images 0SIGNUP 0ExtExport.exe 52hmmapi.dll 53iediagcmd.exe 500ieinstal.exe 490ielowutil.exe 219IEShims.dll 398iexplore.exe 805sqmapi.dll 49