Solved

Combining Get-Mail & Get-Mailboxstatistics To Pull UsageLocation & LastLogonTime

Posted on 2014-03-27
2
2,387 Views
Last Modified: 2014-03-28
I'm trying to use Get-Mailbox & Get-Mailboxstatistics to pull all user's names, UsageLocation, CustomAttribute1 and LastLogonTimes, into a CSV file. If I use the below PowerShell scripts for a single user, it pulls all the information, including LastLogonTime.

"Name","UsageLocation","CustomAttribute1","LastLogonTime"
"Bloggs, Joe","United States","New York","27/03/2014 15:15:01"

However as soon as I replace the username with '-ResultSize 10' or '-ResultSize Unlimited', it only seems to pull LastLogonTime for the last 1 or 2 records, all the rest are just blank.

"Name","UsageLocation","CustomAttribute1","LastLogonTime"
"Johnson, Joe","Canada","Burlington",
"Bloggs, Joe","United States","New York",
"Smith, John","Canada","Whitby","27/03/2014 17:12:39"

How can I get the LastLogonTimes, along with all the other information using these PS commands?

Get-Mailbox "Bloggs, Joe" | Select Name, UsageLocation, CustomAttribute1, @{n='LastLogonTime';e={ ($_ | Get-Mailboxstatistics).LastLogonTime }} | Export-Csv c:\LastLogonTime.csv -encoding UTF8

Open in new window

0
Comment
Question by:bjblackmore
2 Comments
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
Comment Utility
Pipe the "get-mailbox ... -resultsize 10" to sort-object then use select will give the proper results

check this article:http://social.technet.microsoft.com/Forums/exchange/en-US/82d5d38a-0c13-4c16-b1b0-9999c00d354d/mailbox-size-reports-and-other-stuff-exchange-powershell-2010?forum=exchange2010
0
 

Author Comment

by:bjblackmore
Comment Utility
Thanks for the reply. I managed to use that article to produce the below code. Takes about 75minutes to run for all 5,000 users, but manages to pull the information requied. Thanks!

Get-Mailbox -ResultSize Unlimited | sort-object | Select-Object Name, UsageLocation, CustomAttribute1,@{n="LastLogonTime";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.LastLogonTime}} | Export-Csv C:\temp\LastLogonTime.csv -encoding UTF8

Open in new window

0

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

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…

772 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

13 Experts available now in Live!

Get 1:1 Help Now