这是代码,我需要导入CSV并启用从office 365 转发到其他一些电子邮件地址
$creds = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-Credential $creds -Authentication Basic -AllowRedirection
Import-Module MSOnline
Connect-MsolService -Credential $creds
Import-PSSession $Session
$emails = Import-CSV "C:UsersLevDesktopEmail.csv"
ForEach($mail in $emails)
{
Set-Mailbox $mail.Work_email -ForwardingSmtpAddress $mail.home_email -DeliverToMailboxAndForward $true
}
我修复了代码,现在这是一个工作代码。
我的评论是正确的答案:
您需要更改线路
Set-Mailbox -Identity $email.Work_email -DeliverToMailboxAndForward $true $email.home_email -ForwardingSMTPAddress $true
至
Set-Mailbox -Identity $email.Work_email -DeliverToMailboxAndForward $true -ForwardingSMTPAddress $email.home_email
参见设置邮箱中的示例1
$emails=导入CSV C:\path\to\CSV.CSVForEach($email中的$email({设置邮箱$email.email1-转发地址$email_email2-DeliverToMailboxAndForward$true}