In my script I need to know whether an account is a Mail-User
, Mail-Contact
or licensed user account.
Presently I have to know this before-hand
I would probably look at RecipientTypeDetails
to get the Mailbox type for the Mailbox/MailContact.
Maybe do the opposite if you have more MailContacts then Mailboxes in order to optimze it.
And I guess by "Licensed" you mean a UserMailbox? Since you do not mention Azure AD. In Azure AD you have IsLicensed
with Get-MsolUser
.
function GetAccountType($user)
{
$Mailbox = Get-Mailbox -identity $user | select name, RecipientTypeDetails
$type = ""
if ($Mailbox.RecipientTypeDetails -eq "UserMailbox")
{
$type = "Licensed"
}
elseif ($Mailbox.RecipientTypeDetails -eq "SharedMailbox")
{
$type = "Shared"
}
else
{
$MailUser = Get-MailContact -identity $user | select name, RecipientTypeDetails
if ($MailUser.RecipientTypeDetails -eq "MailContact")
{
$type = "Mail-Contact"
}
else
{
$type = "Something else"
}
}
$type
}
$a = GetAccountType -user "userid"
$a | Out-Host