Solved

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

Posted on 2014-03-27
2
2,597 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 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39960937
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
ID: 39961515
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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