Public/Get-MoveRequestLargeItems.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Get-MoveRequestLargeItems {
    <#
.Synopsis
   Takes MoveRequestStatistics object with -IncludeReport specified. Accepts InputObject from pipeline.
.DESCRIPTION
   Long description
.EXAMPLE
   Get-MoveRequestStatistics -IncludeReport | Get-MoveRequestLargeItems
.EXAMPLE
   Import-Clixml .\RequestStatsReport.xml | Get-MoveRequestLargeItems
#>

    [CmdletBinding()]
    [Alias()]
    Param
    (
        # MoveRequestStatistics Object
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            Position = 0)]
        $InputObject
    )

    Begin {
        $properties = "Sender", "Recipient", "FolderName", "Subject", "DateSent", "DateReceived"
        $col = @()
    }
    Process {
        foreach ($user in $InputObject) {   
            if ($null -eq $user.Report) {
                Write-Warning "Report for user '$user' is blank, did you run Get-MoveRequestStatistics with -IncludeReport?"
            }
            foreach ($item in $user.Report.LargeItems) {
                $obj1 = New-Object psobject
                Add-Member -InputObject $obj1 -MemberType NoteProperty -Name DisplayName -Value $user.Identity
                foreach ($prop in $properties) {
                    Add-Member -InputObject $obj1 -MemberType NoteProperty -Name $prop -Value $item.$prop
                }
                Add-Member -InputObject $obj1 -MemberType NoteProperty -Name "MessageSizeMB" -Value ([int]($item.MessageSize / 1MB))
                $col += $obj1
            }
        }
    }
    End {
        $col
    }
}