Hi SpiceHeads,

I’ve just spent about an hour trying to get my Exchange 2010 users export with no luck. I need: DisplayName, MailboxSize, LastLogonTime, PrimarySmtpAddress, AllAliases in one .csv

I need to merge this 2 simplified queries into one:

Get-Mailbox | Get-MailboxStatistics | select DisplayName, databasename, @{expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime, LastLoggedOnUserAccount

Get-Mailbox | Select DisplayName, PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$.EmailAddresses | Where-Object {$.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}

I’m not a shell fan :frowning:

Many thanks in advance,
Jarda

4 Spice ups

I was going to put something helpful together, but I actually found this out on a (ahem) different but similarly awesome site.

The “attribute here” would be the OU you want to search. If you only have one, or want them all, just remove it.

$users = get-mailbox -organizationalunit "attribute here" -resultsize unlimited
$userarray = @()
foreach ($user in $users)
{
$MailUser = $user.UserPrincipalName
$stats= Get-MailboxStatistics $MailUser
$datetime = $stats.LastLogonTime
$date, $time = $datetime -split(' ')
$Maildetails = New-Object -TypeName PSObject -Property @{
DisplayName = $stats.DisplayName
ItemCount = $stats.ItemCount
MailboxSize = $stats.TotalItemSize
LastLogonDate = $date
LastLogonTime = $time
Email = $MailUser
}
$userarray += $Maildetails
} 
$userarray | Export-Csv -Path C:\Users1.csv

Props go to Edward van Biljon.

Hope this works for you!

AJ

1 Spice up

to get all SMTP address

get-mailbox | select -expand emailaddresses alias

try

$users = get-mailbox -resultsize unlimited
$userarray = @()
foreach ($user in $users){
$stats= Get-MailboxStatistics $user.alias
$datetime = $stats.LastLogonTime
$date, $time = $datetime -split(' ')
$Maildetails = New-Object -TypeName PSObject -Property @{
DisplayName = $stats.DisplayName
ItemCount = $stats.ItemCount
MailboxSize = $stats.TotalItemSize
LastLogonDate = $date
LastLogonTime = $time
Email = $user.primarysmtpaddress
Alias=get-mailbox $user.alias | select -expand emailaddresses alias
}
$userarray += $Maildetails
} 
$userarray 

You could also try the following script:

$mailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize unlimited
$output = foreach($mailbox in $mailboxes){
$mailbox | Get-MailboxStatistics | select DisplayName, databasename, @{n="TotalItemSize";e={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime, LastLoggedOnUserAccount, @{n="PrimarySmtpAddress";e={$mailbox.PrimarySmtpAddress}}, @{Name="EmailAddresses";Expression={$mailbox.EmailAddresses | Where-Object {$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}}
}
$output | Select DisplayName, DatabaseName, TotalItemSize, LastLogonTime, LastLoggedOnUserAccount, PrimarySmtpAddress, EmailAddresses | Export-Csv <CSV File Path>

Many thanks!