Link to home
Start Free TrialLog in
Avatar of MarkMichael
MarkMichael

asked on

Powershell - get-mailboxstats

HI Experts,

I'm running powershell commands to pull out lastlogofftime from the mailbox stats, however when running the script:

get-mailbox -resultsize unlimited | get-mailboxstatistics | select DisplayName, LastLogoffTime, LastLoggedOnUserAccount | Export-Csv -Path D:\data\list_lastaccess4th.csv -NoTypeInformation

The output is as follows:
WEB Design             23/10/2013 13:11	DOM\WEBdes
JAMES Jameson        23/10/2013 13:12	DOM\BJC
Christine Bridie       13/09/2013 23:28	DOM\BMCR
Jimmy FLORA		                                DOM\bmf
Shane BENNETT		                        DOM\BSBABC
Laura Davies	        25/06/2012 09:45	DOM\bmb4
Jsaon Cook	        14/05/2013 13:50	DOM\mka
bookings		                                        DOM\RTP
Carmarth	                23/10/2013 12:45	DOM\Carms
YVONNE Jones         10/07/2012 17:35	DOM\mwy1

Open in new window


From the above, there are missing LastLogOffTimes... Although if I query the user manually. The times are there, see below output:

Get-MailboxStatistics bookings | fl

LastLoggedOnUsuerAccount : HQ\RTP
LastLogoffTime          : 23/10/2013 16:55:25
LastLogonTime           : 23/10/2013 16:54:24

Open in new window


Has anyone come across this before?
Avatar of SubSun
SubSun
Flag of India image

It's probably due to the pipeline bug in EMS.. Try..
$(Foreach ($mailbox in get-mailbox -resultsize unlimited){
$mailbox | get-mailboxstatistics | select DisplayName, LastLogoffTime, LastLoggedOnUserAccount
})| Export-Csv -Path D:\data\list_lastaccess4th.csv -NoTypeInformation

Open in new window

Is the Attribute Name correct as its word sensitive and if it doesnt matches the correct word data wont be extracted

- Rancy
Avatar of MarkMichael
MarkMichael

ASKER

Subsun: Same issue unfortunately?

Rancy: The property name is correct, as some of the data is being output for some user accounts but not others. Is that what you mean?
@Rancy, If the attribute name is incorrect then it won’t export the value for all the users. The issue is only for specific users..

@MarkMichael, in the report, is the user who miss the log off time is  different from previous report?
Yes, it's different each time.

Sometimes it will return results for person A, B, C and not D.
Another time it will return results for person A, B, D and not C.
Try this..

$Result = @()
Foreach ($mailbox in get-mailbox -resultsize unlimited){
$Result += get-mailboxstatistics $mailbox.Alias | Select DisplayName,LastLogoffTime,LastLoggedOnUserAccount
}
$Result | Export-Csv -Path D:\data\list_lastaccess4th.csv -NoTypeInformation

Open in new window

Did you get a chance to check it?
Sorry, will try in the morning,
Still same issue unfortunately. Still missing random dates in the output.

Thanks for your help so far though.
If you have some users not exporting data once check with permissions on those objects, also if you take that single user dump do you get those details ?

- Rancy
Yep, if I just run get-mailboxstatistics mpoole, for example... the data is visible.

Same if I export it to csv, the data is visible in the csv file.
can you try to take the data to text and once verify and then work with Excel

- Rancy
verified:

"DisplayName","LastLogoffTime","LastLoggedOnUserAccount"
"Poole",,"DOMAIN\Poole"

Missing LastLogoffTime

I get the same, when I send the output to screen too, I can see several users missing the same fields, but they appear when I view them one by one.
Can you try to run the same script from a different server?
Also try...
Get-mailboxserver | get-mailboxstatistics | select DisplayName, LastLogoffTime, LastLoggedOnUserAccount | Export-Csv -Path D:\data\list_lastaccess4th.csv -NoTypeInformation

Open in new window

Same with both tests, sorry.

Still the same outputs.

I even ran the script from an exchange server in another AD site, same issue.
Sorry.. I cannot reproduce your issue...  Even I have some accounts which miss LastLogoffTime but they also didn't output LastLogoffTime when I run get-mailboxstatistics directly for that account.

Which service pack level and RU you have?
Still stuck on SP1 currently, customer is slow at approving updates!

On the other hand, I've just ran the same scripts on another customer Exchange server who has SP3 installed. Same issue!

There doesn't seem to be any pattern with the output though. Very very odd.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1st one seems to work! Well done :)

Thanks for persisting through this with me!