Determine recursively both COUNT and SUM of all extensions in a folder

耗尽温柔 提交于 2019-11-29 11:28:43

This is one approach:

#Get all items
Get-ChildItem -Path $directory -Recurse |
#Get only files
Where-Object { !$_.PSIsContainer } |
#Group by extension
Group-Object Extension |
#Get data
Select-Object @{n="Extension";e={$_.Name -replace '^\.'}}, @{n="Size (MB)";e={[math]::Round((($_.Group | Measure-Object Length -Sum).Sum / 1MB), 2)}}, Count

Extension Size (MB) Count
--------- --------- -----
mkv          164,03     1
xlsx           0,03     3
dll            0,32     5
lnk               0     1
url               0     1
txt               0     1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!