The simplest answer is mailbox's lastlogontime (Get-MailboxStatistics). But it turnes out to be not quite true.
Attention! The attribute "LastLogonTime" of user's mailbox filled and updated when another user opens user's calendar.
Finally, I found 4 criterias which help to reliably determine that a user is logged into the mailbox.
- "lastlogontime" (Get-MailboxStatistics) - necessary but not sufficient attribute.
- "Languages" (Get-Mailbox) - this attribute filled when user entered into OWA and sometimes filled when entered into Outlook.
- "WorkingHoursTimeZone" (Get-MailboxCalendarConfiguration) - this attribute filled when user entered into OWA and sometimes filled when entered into Outlook. Deffault value - "Pacific Standard Time", so you can use it only if users are in a different time zone.
- "Quick Step Settings" (Get-MailboxFolderStatistics) - this is not an attribute, it is a checking for the presence of a folder "Quick Step Settings" in the mailbox, because it appears only when you open/configure Outlook.
Examples
User 1 - active user. User2 - new user[PS] C:\Windows\system32>Get-Mailbox user2 | Get-MailboxStatistics | ft Displayname,lastlogontime,lastlogofftime
DisplayName LastLogonTime LastLogoffTime
----------- ------------- --------------
User2
[PS] C:\Windows\system32>Get-Mailbox user1 | Get-MailboxStatistics | ft Displayname,lastlogontime,lastlogofftime
DisplayName LastLogonTime LastLogoffTime
----------- ------------- --------------
User1 12/26/2017 11:45:14 PM 12/26/2017 11:59:53 PM
[PS] C:\Windows\system32>Get-Mailbox user2 | ft name,Languages
Name Languages
---- ---------
User2 {}
[PS] C:\Windows\system32>Get-Mailbox user1 | ft name,Languages
Name Languages
---- ---------
User1 {en-US}
[PS] C:\Windows\system32>Get-MailboxCalendarConfiguration user2 | fl identity,WorkingHoursTimeZone
Identity : test.local/Users/User2
WorkingHoursTimeZone : Pacific Standard Time
[PS] C:\Windows\system32>Get-MailboxCalendarConfiguration user1 | fl identity,WorkingHoursTimeZoneFor convenience, I presented the test results in the table:
Identity : test.local/Users/User1
WorkingHoursTimeZone : Eastern Standard Time
Scenarios | lastlogontime | Languages | WorkingHoursTimeZone | "Quick Step Settings" Folder |
New mailbox | - | - | Pacific Standard Time | - |
Active user | Sunday, July 29, 2018 3:31:58 PM | en-US | Eastern Standard Time | Present |
User logged into mailbox by OWA | Sunday, July 29, 2018 10:46:31 PM | ru-RU | Russian Standard Time | - |
User logged into mailbox by Outlook | Sunday, July 29, 2018 10:53:15 PM | - | tzone://Microsoft/Custom | Present |
Another user opened user's calendar | Sunday, July 29, 2018 5:34:37 PM | - | Pacific Standard Time | - |
Another user (with Full Access) opened user's mailbox | Sunday, July 29, 2018 6:34:03 PM | - | Pacific Standard Time | - |
Result
To sum up, to accurately determine whether the user entered the mailbox or not, you can use the following set of commands:$User = "user1"
$User_Enter_LogOn = (Get-Mailbox $User | Get-MailboxStatistics).lastlogontime
$User_Enter_Languages = (Get-Mailbox $User).Languages.Count
$User_Enter_TimeZone1 = (Get-MailboxCalendarConfiguration $User).WorkingHoursTimeZone
$User_Enter_TimeZone2 = (Get-MailboxCalendarConfiguration $User).WorkingHoursTimeZone.ExTimeZone.Id
$User_Enter_QuickStep = (Get-MailboxFolderStatistics $User | where {$_.name -eq "Quick Step Settings"}).name
if (($User_Enter_LogOn -ne $null) -and (($User_Enter_Languages -ge 1) -or ($User_Enter_TimeZone1 -eq "tzone://Microsoft/Custom") -or($User_Enter_TimeZone2 -ne "Pacific Standard Time") -or ($User_Enter_QuickStep -eq "Quick Step Settings")))
{
# User is logged in.
}
else
{
# User did not logged in.
}
No comments:
Post a Comment