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 0
images 0
SIGNUP 0
ExtExport.exe 52
hmmapi.dll 53
iediagcmd.exe 500
ieinstal.exe 490
ielowutil.exe 219
IEShims.dll 398
iexplore.exe 805
sqmapi.dll 49