We help IT Professionals succeed at work.

Get-QADuser and Get-MailboxStatistics help

K B
K B asked
on
I have the quest active roles cmdlets and MSonline cmdlets in one shell...
Any help would be greatly appreciated

I seem to get the first two columns, DisplayName and SamAccountName but not the crucial piece, LastLogonTime

Get-QADUser jones| Select DisplayName,SamAccountName,@{n="LastLogontime";e={(Get-MailboxStatistics $_.Identity).LastLogontime}} | Export-CSV "c:\scripts\jones-2015-2.csv"

Open in new window


Thank you!
K.B.
Comment
Watch Question

K B

Author

Commented:
Came up with this:

Get-QADUser -SizeLimit 0 -LdapFilter "(displayname=a*)(targetAddress=*)" | select DisplayName ,SamAccountName , AccountIsDisabled, @{n = "LastLogontime" ;e= {( Get-MailboxStatistics $_.Name).LastLogontime}} | Export-Csv "C:\scripts\LL-A.csv" -NoTypeInformation

Open in new window

Most Valuable Expert 2015
Distinguished Expert 2019

Commented:
You need remote EO PowerShell, not the MSOnline cmdlets.
K B

Author

Commented:
hmm.  What is the command for that..this is what I typically use:
(I supposed this is to both, correct?)

$cred = Get-Credential "admin@domain.onmicrosoft.com"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

Import-Module MSonline
Connect-MsolService -credential $cred

Open in new window

K B

Author

Commented:
Vasil,

I am trying to incorporate anything that might indicate an issue with off-boarding at this company.  It seems somehow FIM is removing the users license when terminated but this is what is left:

For Example this is a terminated user that is not in the recyclebin:

IsInactiveMailbox                      : False
IsMailboxEnabled                       : True
IsValid                                : True
msExchRecipientDisplayType                            : -2147483642
msExchRecipientTypeDetails                            : 2147483648
msExchRemoteRecipientType                             : 4

What else would I need to gather to insure that the AD object is disabled and that there is no confusion that a mailbox exists in the cloud or (on-premise for that matter).


This is the code I am using (what else should I gather?
Get-QADUser -IncludeAllProperties -SizeLimit 0 -LdapFilter "(&(targetAddress=*)(|(displayname=b*)))" | select DisplayName, msExchRecipientDisplayType, msExchRecipientTypeDetails, msExchRemoteRecipientType, SamAccountName, AccountIsDisabled, @{n = "LastLogontime" ;e= {( Get-MailboxStatistics $_.Name).LastLogontime}} | Export-Csv "C:\scripts\LL-B_C_D.csv"

Open in new window

Most Valuable Expert 2015
Distinguished Expert 2019
Commented:
Nah, that looks fine. So just make sure that Get-MailboxStatistics accepts the parameter you are passing from Get-QADUser. Something like the primarySMTP or mail/WindowsEmailaddress should work.
Top Expert 2015

Commented:
Hi KB..  the field you need for last logon is "lastLogonTimeStamp".

Lastlogon is saved on whichever DC processes your log on and is not replicated.
LastLogonTimeStamp was introduced for the sole purpose of finding inactive accounts, this field is replicated, by default between 9 and 14 days. But will serve your purpose.

You also need to format it into a readable format for your csv... so replace the Latlogon in your select with this....

,@{n="LastLogonTimeStamp";e={[DateTime]::FromFileTime($_.lastLogontimestamp)}}

Open in new window

Top Expert 2015

Commented:
Oh right... last logon for the mailbox... lol - should've read it properly the first time....