Its been a bit since I posted last mainly because I was out on vacations. I been back for a few days now but it had been a bit uneventful. Until today when I was tasked with creating a termination script for over 300 users. I was provided with a list and started working on writing a script that followed our procedures. I don't think I can go into details for privacy reasons but we make some changes to the settings on our Exchange side when we terminate the user, and i noticed that some of the users that I was provided were not Mailbox users but MailUsers and they even threw a few MailContacts in there too.
The command Get-Mailbox does not work for MailUsers or MailContact and they each have their own. I did some digging around to try to find the best way to identify the type of mailbox they are before trying to use the 'Get-' or the 'Set-' commands but I wasn't able to find much. I even reviewed all of the properties for Get-ADUser and Get-ADObject hoping to find anything that would identify all three of them without having to write extra code - I don't normally like to try to write extra code unless I believe its completely necessary. Unfortunately none of it brought me the answer I was seeking.
It wasn't until I was going through the cmdlets that are added with the Exchange Add-in that I found the cmdlet 'Get-User'. I been writing PowerShell for over 2 years now, and quite franky I've never had never seen this particular cmdlet, but it really did made everything so much easier.
Get-User [-Identity <UserIdParameter>] <COMMON PARAMETERS>
Get-User [-Anr <String>] <COMMON PARAMETERS>
SourceCOMMON PARAMETERS: [-AccountPartition <AccountPartitionIdParameter>][-Arbitration <SwitchParameter>][-AuditLog <SwitchParameter>][-ConsumerNetID <NetID>][-Credential <PSCredential>][-DomainController <Fqdn>][-Filter <String>][-IgnoreDefaultScope <SwitchParameter>][-Organization <OrganizationIdParameter>][-OrganizationalUnit <OrganizationalUnitIdParameter>][-PublicFolder <SwitchParameter>][-ReadFromDomainController <SwitchParameter>][-RecipientTypeDetails <RecipientTypeDetails>][-ResultSize <Unlimited>][-SoftDeletedUser <SwitchParameter>][-SortBy <String>]
The regular output is:
PS C:\> get-user Jonatan.Bernal
Jonatan Bernal UserMailbox
It can if you format-list you get the full object: Deserialized.Microsoft.Exchange.Data.Directory.Management.User
The information provided is quite thorough and I don't have to bother what type of mailbox it is which quite frankly I find very useful to only use 1 cmdlet and use the other ones only when they are needed.
I hope that this might help someone out there.
Feel free to leave me a comment and let me know if this was helpful or know any other interesting cmdlets!
Update: well it was pointed out to me by +Lincoln Reedy that the cmdlet that I shared about would unfortunately not work for MailContacts, which again can be a problem. He also shared with me the cmdlet 'Get-Recepient' which would work for any type of object. I haven't quite worked much with this new cmdlet yet, so I'm still doing some research because I saw that you can use an authentication type of federation, so I'm wondering if you can actually get recipients outside of your organization. I'll update when I have more information on this.