0

当我们在 Exchange Online 中创建公用文件夹并启用邮件时,默认电子邮件地址是 @domain.onmicrosoft.com

我们的文件夹名称是“NNNNN_Folder name”,其中 NNNNN 是一个 5 位数字。

我想将公用文件夹的主电子邮件地址设置为 NNNNN@domain.com

我已经尝试了很多变体:

Get-PublicFolder -Recurse -Identity "\X\Y\Z"|
    Sort-Object Identity –Descending| 
    Select-Object -first 4|
    Set-MailPublicFolder  -PrimarySmtpAddress {$_.name.substring(0,5)+"@domain.com"}

并收到有关解释生成的电子邮件地址的错误:

Cannot process argument transformation on parameter 'PrimarySmtpAddress'. Cannot convert value
"$_.name.substring(0,5)+"@domain.com"" to type "Microsoft.Exchange.Data.SmtpAddress". Error: "The email
address "$_.name.substring(0,5)+"@domain.com"" isn't correct. Please use this format: user name, the @ sign,
followed by the domain name. For example, tonysmith@contoso.com or tony.smith@contoso.com."
    + CategoryInfo          : InvalidData: (:) [Set-MailPublicFolder], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-MailPublicFolder
    + PSComputerName        : outlook.office365.com

我还尝试在同一操作中将 PublicFolder 的 EmailAddress 设置为 NNNNN@domain.com。

-EmailAddresses @{$_.name.substring(0,5)+"@domain.com"}

它似乎没有在评估论点还是我错过了其他东西?

如果我Set-MailPublicFolder ...改变 % {$_.name.substring(0,5) + "@domain.com"}

我确实看到了我期望的电子邮件地址。谢谢,

克雷格。

4

1 回答 1

0

看到这个版本。

从 Microsoft 命令文档中,标识参数是必需的(请参阅

我也不确定它是否可以在不指定 foreach 的情况下获取数组并处理每个人。

请参阅此修改版本。

$PublicFolders = Get-PublicFolder -Recurse -Identity "\X\Y\Z"| Sort-Object Identity –Descending | Select-Object -first 4

$PublicFolders | foreach {
                     $NewEmail = "$($_.name.substring(0,5))@domain.com"
                     Write-Host "Settings MailPublicFolder with name $($_.Identity) to $NewEmail" -ForegroundColor Cyan
                     Set-MailPublicFolder -Identity $_.Identity -PrimarySmtpAddress $NewEmail
                  }
于 2017-09-25T18:37:59.633 回答