从每个用户那里获取 PST 文件并将它们按大小排序

Get PST file from every user and sort them into size

大家好,我有一项任务要做,但我没有任何执行计划。 c:\users 中有用户,我必须在 der 目录中获取所有 .pst 文件并将它们加在一起。最后必须将它们排序在 table 中,这样我们就可以看到谁使用最多的磁盘 space 来存储 .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 的帮助下: (UC 释放)

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