2016-11-09 100 views
0

我们刚刚在我们接受的域名和电子邮件地址政策中添加了一个域。虽然我们的许多用户都遵循该政策,但我们有第三个域名,某些用户将其作为其主要地址,而不遵循地址政策。我需要接受这些用户并添加一个格式为[email protected]的SMTP地址。Bulk将SmtpAddress添加到用户Exchange 2010

例如,[email protected](主)具有[email protected]作为别名,并且需要将[email protected]作为SMTP地址添加。

我有下面的代码,但我收到的错误:

$Users = Get-Mailbox -ResultSize Unlimited | Where-Object {($_.PrimarySMTPAddress -like "*domain3.com*)} 
foreach ($a in $Users) { 
    $b = Get-User $a.Primary.SMTPAddress 
    $a.EmailAddresses.Add("$($b.Firstname + "." + $b.Lastname)@domain2.com") 
} 
$Users |%{Set-Mailbox $_.PrimarySMTPAddress -EmailAddresses $_.EmailAddresses 

错误如下:

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "[email protected]" value of type "Microsoft.Exchange.Data.SmtpAddress" to type "Microsoft.Exchange.Configuration.Tasks.UserIdParameter". + CategoryInfo : InvalidData: (:) [Get-User], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-User

Exception calling "Add" with "1" argument(s): "The address '[email protected]' is invalid: "[email protected]" isn't a valid SMTP address. The domain name can't contain spaces and it has to have a prefix and a suffix, such as example.com." At C:\_scripts\SmtpAdd.ps1:4 char:23 + $a.emailaddresses.Add <<<< ("$($b.Firstname + "." + $b.LastName)@domain2.com") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "[email protected]" value of type "Microsoft.Exchange.Data.SmtpAddress" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". + CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox

感谢

回答

1

我认为这个问题与该行开始:

$b = Get-User $a.Primary.SMTPAddress

Get-User未能返回一个有效的用户作为$a.Primary.SMTPAddress没有返回类型Get-User可以使用。这会导致EmailAddresses.Add失败,因为$b为空。 Set-Mailbox失败出于同样的原因为Get-User

试试这个(你还需要做到这一点的Set-Mailbox线):

$b = Get-User $a.Primary.SMTPAddress.ToString()

+0

这与指定'$用户单个用户时,工作= Get-Mailbox“用户名”。我仍然收到上面列出的“异常调用”的“添加”错误,并在OP中输入相同的代码 – hdub

+0

在执行EmailAddresses.Add之前,您可以检查$ b的内容吗? – 2016-11-11 09:12:12

+0

问题似乎源于单独的问题与我们的Exchange环境有关,这个问题已经被修复并且脚本运行了。再次感谢@Tav。 – hdub