How to Determine Account Type?

余生长醉 提交于 2019-12-31 04:13:06

问题


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 and supply it to the script myself.

Is there a better way than this? This only figures between a licensed user and a Mail-Contact-or-Mail-User.

#test for existing account
function GetAccountType($whatusername){

    $isType = [bool](get-mailbox -identity $whatusername -ErrorAction SilentlyContinue)
    if($isType){
        $thisType = "Licensed"
    }else{
        $isType = [bool](get-mailuser -identity $whatusername -ErrorAction SilentlyContinue)
        if($isType){
            $thisType = "Mail-Contact"
        }
    }

    return $thisType
}

回答1:


The RecipientTypeDetails specifies the type of recipients returned.

You can select from the following values with Get-Recipient:

  1. ArbitrationMailbox
  2. ConferenceRoomMailbox
  3. Contact
  4. DiscoveryMailbox
  5. DynamicDistributionGroup
  6. EquipmentMailbox
  7. ExternalManagedContact
  8. ExternalManagedDistributionGroup
  9. LegacyMailbox
  10. LinkedMailbox
  11. MailboxPlan
  12. MailContact
  13. MailForestContact
  14. MailNonUniversalGroup
  15. MailUniversalDistributionGroup
  16. MailUniversalSecurityGroup
  17. MailUser
  18. PublicFolder
  19. RoleGroup
  20. RoomList
  21. RoomMailbox
  22. SharedMailbox
  23. SystemAttendantMailbox
  24. SystemMailbox
  25. User
  26. UserMailbox

What I am understanding from your case is that you need UserMailbox, User , MailUser , MailContact

I don't have an exchange setup right now. BUt you can set off with these value. It falls under Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails[]




回答2:


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


来源:https://stackoverflow.com/questions/41228557/how-to-determine-account-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!