在我的脚本中,我需要知道帐户是Mail-User
,Mail-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
}
答案 0 :(得分:2)
我可能会查看RecipientTypeDetails
以获取邮箱/ MailContact的邮箱类型。
如果您有更多MailContacts然后邮箱以优化它,可能会反过来。
我想通过"许可"你的意思是UserMailbox?由于您未提及Azure AD。在Azure AD中,IsLicensed
为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
答案 1 :(得分:2)
RecipientTypeDetails 指定返回的收件人类型。
您可以使用 Get-Recipient :
从以下值中进行选择我从您的案例中了解到,您需要 UserMailbox ,用户, MailUser , MailContact < / p>
我现在没有交换设置。你可以用这些值来抵消。 它属于 Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails []