0

在自学时,我对 powershell 仍然很陌生,但是我似乎无法在 Exchange 2010 上使用它,在 CSV 中使用用户列表并设置外出回复。我在 OOO 消息中调用了一个变量 $Email,但它似乎永远不会正确输出。请帮忙,我不知所措!

我的 CSV 很简单:

Users,Email Test-1,John.J.Smith Test-2,Sammy.R.Hagar

     $content = Import-Csv "C:\Scripts\File\files.csv" -Header "Users", "Email"

    ForEach ($_.Users in $content) {
        Set-MailboxAutoReplyConfiguration $_.Users -AutoReplyState enabled -ExternalAudience all -InternalMessage "$_.Users no longer works here, please reach them at $_.Email" -ExternalMessage "$_.Ysers no longer works here, please reach them at $_.Email"
    }

 Exit

我在此脚本中更改了一些名称以使其匿名,但是当我运行此脚本时,它告诉我在我的域中找不到对象“用户”。是什么赋予了?!?

4

1 回答 1

0

如果您的 csv 文件中已有标题行,则不应使用Import-CSV. 对于 foreach 循环,您创建一个新的“循环变量”并遍历您从 csv 文件创建的数组。

$content = Import-Csv "C:\Scripts\File\files.csv" 
ForEach ($Element in $content) {
    Set-MailboxAutoReplyConfiguration $Element.Users -AutoReplyState enabled -ExternalAudience all -InternalMessage "$($Element.Users) no longer works here, please reach them at $($Element.Email)" -ExternalMessage "$($Element.Users) no longer works here, please reach them at $($Element.Email)"
}

另一种方法是像这样使用管道:

Import-Csv "C:\Scripts\File\files.csv" | 
    ForEach-Object {
        Set-MailboxAutoReplyConfiguration $_.Users -AutoReplyState enabled -ExternalAudience all -InternalMessage "$($_.Users) no longer works here, please reach them at $($_.Email)" -ExternalMessage "$($_.Users) no longer works here, please reach them at $($_.Email)"
    }
于 2018-03-23T22:44:00.460 回答