Help getting mailbox size for a group of users using Powershell

Posted on 2012-08-22
Last Modified: 2012-08-23
Greetings Powershell Gurus,
I have a list of users that I generated with the following command:

Get-qaduser –department sales | select-Object logonname

The list of users looks like the following:


I would like to now find the mailbox size for these users.  I know that I’m going to use the get-mailboxstatistics commandlet.  I thought the following would work:

$Users = Get-qaduser –department facilities | select-Object logonname
foreach ($User in $Users) {Get-MailboxStatistics -Identity $user -Server mail01}

When I run the command above, I get the following error that I’m having trouble working through:

Get-MailboxStatistics : Cannot bind parameter 'Identity'. Cannot convert the "@{LogonName=emusta}" value of type "Selected.Quest.ActiveRoles.ArsPow
erShellSnapIn.Data.ArsUserObject" to type "Microsoft.Exchange.Configuration.Tasks.GeneralMailboxIdParameter".
At line:3 char:59
+ foreach ($User in $Users) {Get-MailboxStatistics -Identity <<<<  $user -Server mail01}
    + CategoryInfo          : InvalidArgument: (:) [Get-MailboxStatistics], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

Any ideas on what I’m doing wrong here.  Any help would be greatly appreciated.

Question by:ndalmolin_13
    LVL 13

    Expert Comment

    You can use following. Use have to change some parts. But just read the commentary and you know what you need to change and what it does.

    #AD Setting for Multi Domain Forest
    Set-ADServerSettings -ViewEntireForest $true
    #Array for Reporting Objects
    $Summary = @()
    #Array of Requested Dept Codes Which Should AD Group Named After Them
    $ADGroups = "Group1","Group2","Group3","Group4","Group5","Group6","Group7"
    foreach ($ADGroup in $ADGroups)
    #Pull AD Group Members
    $dPart = (get-group $ADGroup).members
    foreach ($dUser in $dPart)
    #Get Mailbox Stats for Group Member
    $mbstats = get-mailboxstatistics $dUser
    #Only Report on Users with Actual Mailboxes
    #Convert Size Into GBs
    $mbsize = ("{0:N2}" -f ($mbstats.TotalItemSize.Value.ToMB()/1024))
    #Create New PowerShell Object and Assign Data to It
    $uEntry = new-Object PSObject
    $uEntry | add-Member -memberType noteProperty -name "Display Name" -Value $mbstats.DisplayName
    $uEntry | add-Member -memberType noteProperty -name "Mailbox Size (GB)" -Value $mbsize
    $uEntry | add-Member -memberType noteProperty -name "Last Logon Time" -Value $mbstats.LastLogonTime
    #Add Entry to Summary Array
    $Summary += $uEntry
    #Export Summary Info to CSV File
    $Summary | Sort-Object {[int]$_."Mailbox Size (GB)"} -Descending | Export-CSV Mailboxes_By_AD_Group.csv -NoTypeInformation

    Open in new window

    LVL 6

    Accepted Solution

    $Users = Get-qaduser –department facilities | select-Object -expand logonname
    foreach ($User in $Users) {Get-MailboxStatistics -Identity $user -Server mail01}

    Open in new window

    LVL 16

    Expert Comment

    by:Rajitha Chimmani
    If you are not restricted to use just the logonname, You can use it this way with displayname or primarysmtpaddress,

    $Users = Get-qaduser –department facilities
    foreach ($User in $Users) {Get-MailboxStatistics -Identity $user.displayname -Server mail01}

    $Users = Get-qaduser –department facilities
    foreach ($User in $Users) {Get-MailboxStatistics -Identity $user.primarysmtpaddress -Server mail01}

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    A post on a forum I visit frequently mobilized me to create a script to remove a password (the one required to open a file) from any number of Word files. Because nobody would want to open a 100 files and manually save them... Of course, you have t…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now