Quantcast
Channel: Exchange Server 2013 - Administration, Monitoring, and Performance 论坛
Viewing all articles
Browse latest Browse all 8719

Powershell script to export Mailbox Size, OU, Item Count and Display name

$
0
0

I took this script from another Technet post, but haven't been able to get it to run correctly. I keep getting an error stating I cannot call a method on a null-valued expression.

Here is the script:

                          

$mbxStats = @()

$Mailboxes = Get-Mailbox -ResultSize Unlimited | 

 ForEach-Object {

            # Retrieve the identiry and store it in the variable $_
            $stats = Get-MailboxStatistics -id $_         

            # Create a new instance of a .Net object
            $mbx = New-Object System.Object

            # Add user-defined customs members: the records retrieved with the three PowerShell commands
            $mbx | Add-Member -MemberType NoteProperty -Value $stats.Displayname -Name DisplayName
            $mbx | Add-Member -MemberType NoteProperty -Value $_.organizationalUnit -Name OrganizationalUnit          
            $mbx | Add-Member -MemberType NoteProperty -Value $(Get-MailboxDatabase -id $_.database).storagegroup -Name StorageGroupName
            $mbx | Add-Member -MemberType NoteProperty -Value $stats.ItemCount -Name ItemCount
            $mbx | Add-Member -MemberType NoteProperty -Value $stats.TotalItemSize.value.ToMB() -Name TotalSize

            # Add right hand operand to value of variable ($mbx) and place result in variable ($mbxStats)
            $mbxStats += $mbx
      }

# Pipe the result and sort by TotalSize. Export to .csv file. Use Unicode format
$mbxStats | Sort-Object TotalSize | Export-Csv -Encoding 'Unicode' C:\Users\administrator.HOSTING\Desktop\report.csv

I'm not very fluent in Powershell so my debuggings is very limited.


Viewing all articles
Browse latest Browse all 8719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>