#region IsIn 判断某个用户是否在邮件组中 Function IsIn([string]$User,[string] $GroupName){ if($User -eq "" -or $GroupName -eq ""){ Write-Warning "参数丢失,正确的格式为 IsIn userName GroupName" break } Write-Host "【Start】 Search $user in ("$GroupName ") group" $Result = Get-DistributionGroupMember -ResultSize unlimited $GroupName | where {$_.name -eq $User -or $_.PrimarySmtpAddress -eq $user} if($Result -eq $null){ $SubGroups = Get-DistributionGroupMember -ResultSize unlimited $GroupName | where {($_.RecipientType -eq "MailUniversalDistributionGroup") -or ($_.RecipientType -eq "MailUniversalSecurityGroup")} | select name if($SubGroups -ne $null){ ForEach($SubGroup in $SubGroups){ IsIn $user $SubGroup.name } }else{ Write-Host -fore red "$user is not in group ("$GroupName ")," $result=Get-Mailbox -Identity $User -errorAction silentlyContinue if($result -eq $null){ Write-Warning "The email account $user is not exist." break } } } else{ Write-Host $User "is found in group" $GroupName -foregroundcolor green } } #Example IsIn "用户邮箱" "邮件组名称" #endregion
本文出自 “bxing” 博客,请务必保留此出处http://bxing.blog.51cto.com/1677994/1877927
原文地址:http://bxing.blog.51cto.com/1677994/1877927