daknetworks.com

You are here: Blog All Enabled Accounts on Exchange Sorted by Last Name

All Enabled Accounts on Exchange Sorted by Last Name

Them: Can you give us a list of All Enabled Accounts on Exchange Sorted by Last Name?

Me: Sure.

The problem becomes this is trickier than it seems.

There are 3 commands that are helpful:

get-mailbox: a list of all the mailboxes, including SHARED, RESOURCE, EQUIPMENT, ROOM but not including contacts, mailuser, distributiongroup, etc. Disabled accounts are included. There is no disabled/enabled property.
Use the following to see what it shows and the number of items: Get-Mailbox |GroupRecipientTypeDetails |Selectname,count

get-recipient: a list of all recipients including mailboxes, contacts, mailuser, distributiongroup, etc. Basically, any type of existing Exchange Online recipient.
Use the following to see what it shows and the number of items: Get-recipient|GroupRecipientTypeDetails |Selectname,count

get-user: get the USER objects from Active Directory, including the users without mailboxes and disabled users.
Use the following to see what it shows and the number of items: Get-user |GroupRecipientTypeDetails |Selectname,count

Knowing the above, we can put together a command that lists out all the USERS from AD that is enabled:

Get-User -RecipientTypeDetails UserMailbox -sortby lastname |where {$_.UseraccountControl -ne “*accountdisabled*”} |Select samaccountname

Contact Dak Networks

Please contact us at the following.