从每个用户获取PST文件并按大小排序



嘿,伙计们,我有一个任务要做,但我没有任何计划如何执行它。在c:users中有用户,我必须将所有.pst文件放在一个目录中并将它们加起来。最后必须在一个表中对它们进行排序,以便我们可以看到谁为.pst文件使用了最多的磁盘空间

你有没有试过"至少"试着写点什么?

无论如何,您可以从以下几行开始:


$path = Get-ChildItem -Path C:users -Filter "*.pst" -Recurse | Select-Object -ExpandProperty Fullname
For($i=0; $i -lt $path.Count; $i++){
[pscustomobject] @{
PSTsFound = $path[$i]
}
}

在Pat Richard的帮助下:(加州大学释放)

function Get-PstFiles {
[CmdletBinding(SupportsShouldProcess = $True)]
param(
[Parameter(Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[string]$path,
[Parameter(Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[string]$filter = "*.pst",
[Parameter(Position = 2, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, Mandatory = $False)]
[ValidatePattern(".csv")]
[string]$file
)
Begin{
$PSTFiles = @()
}
Process{
Get-ChildItem $path -recurse -Filter $filter | ? {$_.PSIsContainer -eq $False} | % {
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Directory $_.DirectoryName
$obj | Add-Member NoteProperty Name $_.Name
$obj | Add-Member NoteProperty "Size in MB" ([System.Math]::Round(($_.Length/1mb),2))
$obj | Add-Member NoteProperty Owner ((Get-ACL $_.FullName).Owner)
$PSTFiles += $obj
}
}
end{
if ($file){
$PSTFiles | Export-CSV "$file" -NoTypeInformation 
}else{
$PSTFiles
}
}
}

语法如下:Get-PstFiles [[-path] ] [[-filter] ] [[-file] ] [-WhatIf] [-Confirm] []

示例:Get-PstFiles -path C:Users

最新更新