Export a list of all mailboxes, mailbox sizes, archive mailbox sizes

I'm looking for a way to export a list of all mailboxes, then when breaking the export out to csv, export the mailbox size as well as the archive mailbox size per mailbox...

Has anyone done this and willing to hook me up? :-) Please...
Christian HansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MAS (MVE)EE Solution Guide - Technical Dept HeadCommented:
Hi Christian Hans,
Please try this command and let me know
Import-CSV users.csv| Foreach {Get-Mailbox $_.mailbox} | Select-Object name,@{n="Mailbox Size(MB)";e={(Get-MailboxStatistics $_).totalItemsize.value.toMB()}},
	@{n="Archive Size(MB)";e={(Get-MailboxStatistics -archive $_).totalItemsize.value.toMB()}} | Export-Csv c:\temp\export.csv

Open in new window

0
Thomas UCommented:
I saw this and tried it, but the code scrambles my csv. So I found a better one that is more suitable for me. Maybe you can profit as well.

cheers
Thomas

ps1 file
$Mailboxes = @(get-Mailbox)
$report = @()

foreach ($Mailbox in $Mailboxes)
    {
        $mailboxonly = Get-Mailbox $Mailbox
        $mailboxstate = Get-Mailbox $Mailbox | Get-MailboxStatistics
        $mailboxstateA = Get-Mailbox $Mailbox | Get-MailboxStatistics -archive

        $inpObj = New-Object PSObject
        $inpObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailboxstate.DisplayName 
        $inpObj | Add-Member -MemberType NoteProperty -Name "PrimarySmtpAddress" -Value $mailboxonly.PrimarySmtpAddress
        $inpObj | Add-Member -MemberType NoteProperty -Name "Database" -Value $mailboxstate.Database
        $inpObj | Add-Member -MemberType NoteProperty -Name "MailboxSize" -Value $mailboxstate.totalitemsize
        $inpObj | Add-Member -MemberType NoteProperty -Name "ArchiveDatabase" -Value $mailboxonly.ArchiveDatabase
        $inpObj | Add-Member -MemberType NoteProperty -Name "ArchiveSizeenter image description here" -Value $mailboxstateA.TotalItemSize
        $report += $inpObj
    }

$report | export-csv c:\temp\report.csv -NoTypeInformation -Delimiter ";"

Open in new window

0
Christian HansAuthor Commented:
Thanks Thomas... thats a cool script... I cant get it to work though unfortunately...

Error:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "firstname lastname" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter".

Any ideas?

MAS (MVE), the commands you provided, I run successfully, but theres no data pulled back... so maybe its missing something still?

I appreciate your help guys!
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Thomas UCommented:
Hi Christian

Hmm..what Exchange server version do you have? I just tried it, no errors.

regards
Thomas
0
Christian HansAuthor Commented:
2010 CU20
0
Thomas UCommented:
hmm

please try editing the first line in the scriptfile

$Mailboxes = @(get-Mailbox username)

Open in new window


As username use any mailboxalias. best would be a name without spaces or specia characters in it. thats how I would investigate.
0
Christian HansAuthor Commented:
No luck unfortunately...

Im also playing with the idea of creating something along these lines:

Get-Mailbox -ResultSize 10 | Foreach-Object {

    $mbx = $_ | Select SamAccountName,UserPrincipalName,ArchiveName,ArchiveQuota,Alias,DisplayName,PrimarySmtpAddress,RecipientTypeDetails,Identity
    $stats = Get-MailboxStatistics $_ | Select DisplayName,ItemCount,TotalItemSize
    $statsa = Get-MailboxStatistics -Archive $_ | Select DisplayName,ItemCount,TotalItemSize

    New-Object -TypeName PSObject -Property @{
        Alias = $mbx.Alias
        ArchiveName = $mbx.ArchiveName
        ArchiveQuota = $mbx.ArchiveQuota
        DisplayName = $mbx.DisplayName
        ArchiveDisplayName = $statsa.DisplayName
        Identity = $mbx.Identity
        ItemCount = $stats.ItemCount
        ArchiveItemCount = $statsa.ItemCount
        PrimarySmtpAddress = $mbx.PrimarySmtpAddress
        RecipientTypeDetails = $mbx.RecipientTypeDetails
        SamAccountName = $mbx.SamAccountName
        TotalItemSize = $stats.TotalItemSize
        ArchiveTotalItemSize = $statsa.TotalItemSize
        UserPrincipalName = $mbx.UserPrincipalName
    }

} | Export-Csv C:\Output\MailboxData.csv -NoTypeInformation

Error:

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "Joe Smith" value of type "Deserialized.Microsoft.Exchange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-MailboxStatistics], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxStatistics
0
Thomas UCommented:
But the Get-MailboxStatistics and Get-MailboxStatistics -Archive do not get any errormessages, do they?

Please use "$Mailboxes = @(get-Mailbox YourALIAS)" in the code to test it. Your Mailboxalias...I don't think it is "joe smith"

regards
Thomas
0
MAS (MVE)EE Solution Guide - Technical Dept HeadCommented:
Did you try this?
(Get-Mailbox) | Select-Object name,@{n="Mailbox Size(MB)";e={(Get-MailboxStatistics $_).totalItemsize.value.toMB()}}, @{n="Archive Size(MB)";e={(Get-MailboxStatistics -archive $_).totalItemsize.value.toMB()}}

Open in new window


To export to CSV you can use " | Export-csv c:\test\export.csv" at the end.
0
Thomas UCommented:
@MAS That works very well for me now.

@christian use MAS script above add
| export-csv c:\temp\mbox.csv -NoTypeInformation

Open in new window

at the end

and you are served ;)
1
Christian HansAuthor Commented:
I really appreciate your help on this guys... I just don't get why this isn't working for me.

Just to confirm, I can get the commands to work by themselves:

PS C:\> Get-Mailbox -Identity jsmith | FL SamAccountName,UserPrincipalName,ArchiveName,ArchiveQuota,Alias,DisplayName,PrimarySmtpAddress,RecipientTypeDetails,Identity

SamAccountName       : jsmith
UserPrincipalName    : joe.smith@contoso.com
ArchiveName          : {Personal Archive - Joe Smith}
ArchiveQuota         : 50 GB (53,687,091,200 bytes)
Alias                : jsmith
DisplayName          : Joe Smith
PrimarySmtpAddress   : joe.smith@contoso.com
RecipientTypeDetails : UserMailbox
Identity             : contoso.local/Users/Joe Smith


PS C:\> Get-MailboxStatistics  -Identity jsmith | FL DisplayName,TotalItemsize

DisplayName   : Joe Smith
TotalItemSize : 610 MB (639,609,385 bytes)


PS C:\> Get-MailboxStatistics -Archive  -Identity jsmith | FL DisplayName,TotalItemsize

DisplayName   : Personal Archive - Joe Smith
TotalItemSize : 4.951 KB (5,070 bytes)


Regarding your other question;

PS C:\> (Get-Mailbox) | Select-Object name,@{n="Mailbox Size(MB)";e={(Get-MailboxStatistics $_).totalItemsize.value.toMB()}}, @{n="Archive Size(MB)";e={(Get-MailboxStatistics -archive $_).totalItemsize.value.toMB()}}

Name             Mailbox Size(MB) Archive Size(MB)
----             ---------------- ----------------
User 1                                          
User 2                                      
User 3                                
User 4                                

 = Although the users listed definitely do have mailboxes and archive mailboxes

PS C:\> $Mailboxes = @(Get-Mailbox jsmith) | Select-Object name,@{n="Mailbox Size(MB)";e={(Get-MailboxStatistics $_).totalItemsize.value.toMB()}}, @{n="Archive Size(MB)";e={(Get-MailboxStatistics -archive $_).totalItemsize.value.toMB()}}

PS C:\>

 = no results
0
Thomas UCommented:
That is absolutely strange. I get all the infos on an exchange 2010, even not with the SP and CU you have. I also tested an Exchange 2013 shell. there it works as well, even we do not have an archive...

Do you open the Exchange Management Shell on the Exchange itself or are the manage tools installed on a different Server?
Do you have another user that has Exchange Adminrights, can logon to the Exchange and open the Shell? Try it with that one as well.
0
MAS (MVE)EE Solution Guide - Technical Dept HeadCommented:
This is weird. It should work.  :(
0
Thomas UCommented:
Somehting I saw above:

If you execute that:
$Mailboxes = @(Get-Mailbox jsmith) | Select-Object name,@{n="Mailbox Size(MB)";e={(Get-MailboxStatistics $_).totalItemsize.value.toMB()}}, @{n="Archive Size(MB)";e={(Get-MailboxStatistics -archive $_).totalItemsize.value.toMB()}}

Open in new window

You do not get results, the results are saved into the variable $Mailboxes. After you executed the above, you need to write
$Mailboxes

Open in new window

in the Shell to see the results
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.