我正在写一个foreach循环脚本我以前做过这个,但是这个脚本给了我一个问题。它在我手动输入名称时有效,但当我尝试从txt文件中提取时出现错误。
$mailboxes = Get-Mailbox joerod
foreach ($mailbox in $mailboxes)
{
$user = $mailbox.alias
Write-Host "Processing... $user"
$mailbox.EmailAddresses += [Microsoft.Exchange.Data.CustomProxyAddress] ("X500:/o=OrgName/ou=First Administrative Group/cn=Recipients/cn=$user")
Set-Mailbox -Identity $mailbox.alias -EmailAddresses $mailbox.EmailAddresses
}
答案 0 :(得分:1)
添加以下行并获得我想要的内容
$mailboxes = Get-Mailbox -OrganizationalUnit "ou=users,dc=contoso,dc=local"