Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-27
2
Medium Priority
?
2,757 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

597 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