如何确定帐户类型?

时间:2016-12-19 18:10:37

标签: powershell office365

在我的脚本中,我需要知道帐户是Mail-UserMail-Contact还是许可的用户帐户。

目前我必须事先了解这一点并自己提供给脚本。

有比这更好的方法吗?这仅在许可用户和邮件联系人或邮件用户之间进行计算。

#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
}

2 个答案:

答案 0 :(得分:2)

我可能会查看RecipientTypeDetails以获取邮箱/ MailContact的邮箱类型。

如果您有更多MailContacts然后邮箱以优化它,可能会反过来。

我想通过"许可"你的意思是UserMailbox?由于您未提及Azure AD。在Azure AD中,IsLicensedGet-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

答案 1 :(得分:2)

RecipientTypeDetails 指定返回的收件人类型。

您可以使用 Get-Recipient

从以下值中进行选择
  1. ArbitrationMailbox
  2. ConferenceRoomMailbox
  3. 联系
  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. 用户
  26. UserMailbox
  27. 我从您的案例中了解到,您需要 UserMailbox 用户 MailUser MailContact < / p>

    我现在没有交换设置。你可以用这些值来抵消。 它属于 Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails []