Exchange管理Shell批量添加通讯组成员脚本间歇性失效问题排查求助
Exchange管理Shell批量添加通讯组成员脚本间歇性失效问题排查求助
大家好,我正在Exchange管理Shell里运行下面的脚本,目的是把一份Excel文件(包含姓名、邮箱两列)里的所有邮箱账号添加到指定通讯组。目前的思路是先导入CSV文件,指定目标通讯组,然后循环遍历每条记录来完成成员添加操作。
但现在遇到了一个很棘手的问题:明明很多邮箱账号是确定存在的,脚本却返回“User with email not found”的提示,大概只有40%的账号能被成功识别并添加,剩下60%都找不到——可我手动验证过这些邮箱确实是存在的。想请各位帮忙看看我的脚本有没有什么问题?
$csvPath = "C:\Users\Desktop\emailNames.csv" # Replace with the name of the distribution group $groupName = "emailOfficer" # Import the CSV file $members = Import-Csv -Path $csvPath # Loop through the CSV and add members to the distribution group foreach ($member in $members) { $email = $member.email.Trim() $user = Get-Mailbox | Where-Object { $_.PrimarySMTPAddress -ieq $email.Trim() } # $user = Get-Mailbox | Where-Object { $_.PrimarySMTPAddress -ilike "*$email*" } Write-Host($user) if ($user) { Add-DistributionGroupMember -Identity $groupName -Member $user.Identity Write-Host "Added $($user.PrimarySMTPAddress ) to $groupName" } else { Write-Host "User with email $email not found." } }
备注:内容来源于stack exchange,提问作者unknown techh
相关产品推荐
相关产品推荐

