获取每个用户.pst文件的大小 [英] Get Size of every users .pst Files
本文介绍了获取每个用户.pst文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.pst
文件的大小。我的问题是,我真的不知道如何创建一个Foreach
来汇总用户目录中的所有.pst
文件。别笑,我知道Foreach循环是完全错误的
$arr = Get-ChildItem \Serverusersz01 | Where-Object {$_.PSIsContainer} | Foreach-Object {$_.Name} #Gets names of all Folders in this Directory
$Pfad = \Serverusersz01
foreach ($arr in $Pfad){
$Sum = Get-ChildItem -Path . -Include *pst | measure Length -sum
}
$Sum
pst
我建议首先获取一个对象数组,其中保存了推荐答案文件的全名及其长度。这样,您还可以将此信息导出到CSV文件以供进一步分析。
然后使用该数组计算总大小:
$Pfad = '\Serverusersz01'
# leave out -Recurse if you do NOT want to include files in subdirectories
$allPstFiles = Get-ChildItem -LiteralPath $Pfad -Filter '*.pst' -File -Recurse | Select-Object FullName, Length
# you can output this on screen or write it to disk as Csv file, see
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv
# next get the sum of all sizes
$totalSize = ($allPstFiles | Measure-Object -Property Length -Sum).Sum
$totalSize
根据您的最新评论,我了解到您希望每个用户拥有所有*.pst文件的总和
(==>;文件夹名称在$Verzeichniss
内),格式为GB,小数点后只有两位数字。
在这种情况下,请尝试:
$Verzeichniss = '\Serverusersz01'
$userFolders = Get-ChildItem -LiteralPath $Verzeichniss -Directory
$Gesamt = foreach ($dir in $userFolders) {
# take the username from the folder name
$userName = $dir.Name
# find all *.pst files for this user
Get-ChildItem -LiteralPath $dir.FullName -Filter '*.pst' -File -Recurse |
# group them by a common property, in this case they all have .pst extension
Group-Object {$_.Extension} |
Select-Object @{Name = 'Name'; Expression = { $userName }},
@{Name = 'TotalSizeInGB'; Expression = { '{0:F2}' -f (($_.Group | Measure-Object Length -Sum).Sum / 1Gb ) }}
}
$Gesamt | Sort-Object -Property TotalSizeInGB -Descending | Select-Object -First 30
这篇关于获取每个用户.pst文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文