none
Need a list of mail users with spesific info RRS feed

  • Question

  • Hello!

    I am trying to export a list of all mail enabled user with some spesific info. 

    The columns i need are DisplayName, EmailAddress, Office/Department and LastLogonTime.

    So far i have tried these two scripts:

    Import-Module ActiveDirectory
    Get-ADUser -Properties DisplayName, EmailAddress, LastLogonDate, Department -Filter {EmailAddress -like '*'} |
    select DisplayName, EmailAddress, LastLogonDate, Department |
    Export-CSV "C:\Temp\Brukere.csv"

    This one gets me a nice list but the problem with this one is that we have many users in AD with with E-mail set in the E-mail field on the General tab in user properties, but the mailbox does not exist in exchange. Can i export only exchange users using the AD module and Get-ADUser?

    The other one:

    Get-Mailbox -ResultSize Unlimited -RecipientType UserMailbox | 
    Get-MailboxStatistics | 
    Sort LastLogonTime | 
    Select DisplayName,PrimarySMTPAddress,Office,LastLogonTime | Export-csv C:\temp\brukere.csv

    This one i tried using the Exchange Management Shell. The csv file i get from this only contains DisplayName, the other columns i need are blank. 

    Can anyone point me in the right direction to where my fault is?

    Thanks!

    Thursday, November 2, 2017 11:43 AM

Answers

  • You should be able to to select only user objects with an Exchange mailbox using an LDAP filter; e.g.:


    Get-ADUser -LDAPFilter "(&(msExchRecipientDisplayType:1.2.840.113556.1.4.803:=1073741824)(msExchRecipientTypeDetails:1.2.840.113556.1.4.803:=1))" -Properties DisplayName, EmailAddress, LastLogonDate, Department

    The msExchRecipientDisplayType attribute will have the 31st bit (decimal 1073741824) set and the msExchRecipientTypeDetails attribute will have the 1st bit set if the object is a user mailbox.

    The values are from here:

    https://blogs.technet.microsoft.com/benw/2007/04/05/exchange-2007-and-recipient-type-details/

    The LDAP search filter syntax is available here:

    https://msdn.microsoft.com/en-us/library/aa746475.aspx

    (1.2.840.113556.1.4.803 is the LDAP_MATCHING_RULE_BIT_AND OID - this allows you to filter on specific bits in a numeric value.)


    -- Bill Stewart [Bill_Stewart]



    Monday, November 6, 2017 3:46 PM
    Moderator

All replies

  • Hi EvenOps,

    For your first question: Yes you have to get the exchange users and then get the users from active directory.

    For your second question : Please go through the link and check with the parameters that you would like to extract.

    Get-Mailbox

    Get-MailboxStatistics


    Naveen Basati

    Thursday, November 2, 2017 12:35 PM
  • get-mailbox is different that mail user. you will get all mailboxes and not just mail enabled users.

    You may have to use get-recipient and use appropriate filters to filter mail enabled users


    Thanks & Regards Ramandeep Singh

    Thursday, November 2, 2017 12:39 PM
  • I have set the -RecipientType to UserMailbox so that it only exports usermailbox and not rooms, groups and so on.
    Thursday, November 2, 2017 1:11 PM
  • Bump. Still need some help here. I have tried finding the right parameters reffered to from Karur, but i cant seem to find the ones im after. 

    Get-Mailbox –Resultsize Unlimited –Database MailboxDatabaseName | Get-MailboxStatistics | Sort LastLogonTime | Select Displayname, LastLogOnTime

    That is a proporsition from microsoft, but i cant get anything to work the way i want. Is it at all possible to get all the results im after with one script? Or maybe i need to export some from exchange and some from AD and merge the results after?

    Monday, November 6, 2017 9:44 AM
  • Since most of the information you seek is in AD then you will have to query both and combine the results.


    \_(ツ)_/

    Monday, November 6, 2017 2:41 PM
  • You should be able to to select only user objects with an Exchange mailbox using an LDAP filter; e.g.:


    Get-ADUser -LDAPFilter "(&(msExchRecipientDisplayType:1.2.840.113556.1.4.803:=1073741824)(msExchRecipientTypeDetails:1.2.840.113556.1.4.803:=1))" -Properties DisplayName, EmailAddress, LastLogonDate, Department

    The msExchRecipientDisplayType attribute will have the 31st bit (decimal 1073741824) set and the msExchRecipientTypeDetails attribute will have the 1st bit set if the object is a user mailbox.

    The values are from here:

    https://blogs.technet.microsoft.com/benw/2007/04/05/exchange-2007-and-recipient-type-details/

    The LDAP search filter syntax is available here:

    https://msdn.microsoft.com/en-us/library/aa746475.aspx

    (1.2.840.113556.1.4.803 is the LDAP_MATCHING_RULE_BIT_AND OID - this allows you to filter on specific bits in a numeric value.)


    -- Bill Stewart [Bill_Stewart]



    Monday, November 6, 2017 3:46 PM
    Moderator