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

问题描述

大家好,我有一项任务要做,但我没有任何计划如何执行它。 c:\users 中有用户,我必须获取 der 目录中的所有 .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 的帮助下: (UC 释放)

function Get-PstFiles {

  [CmdletBinding(SupportsShouldProcess = $True)]
  param(
        [Parameter(Position = 0,ValueFromPipeline = $True,ValueFromPipelineByPropertyName = $True,Mandatory = $False)]
        [ValidateNotNullOrEmpty()]
        [string]$path,[Parameter(Position = 1,Mandatory = $False)]
        [ValidateNotNullOrEmpty()]
        [string]$filter = "*.pst",[Parameter(Position = 2,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