【发布时间】:2019-09-27 13:12:16
【问题描述】:
我想从一个安全组中获取所有用户并提取他们的电子邮件。收到他们的电子邮件后,我想将该电子邮件地址列表传递给一个函数(理想情况下是一个 for 循环),以向该安全组中的所有用户发送电子邮件。任何帮助表示赞赏。
$users = Get-ADGroupMember -Identity 'IS-Test-GRP' -Recursive |
Select-Object -Unique | Get-ADUser -Properties Mail | Select-Object Mail
Foreach($user in $users)
{
Send-MailMessage -From joetest@mail.com -To $user.mail -Subject 'Migrating
File Share' -Body 'Hello All,
I will be migrating the share folder < > from app02 to app03. Once
completed I will email all users the new file path location to access the
share. If you will be needing help creating a new shortcut, please contact
the help desk. Any issues or questions, please let me know. -Thank you' -
SmtpServer 'mail.server.com'
}
【问题讨论】:
-
那么哪一个失败了——用户枚举,还是邮件发送?将
$user.mail插入您的Foreach,以便您看到您收到了正确的电子邮件。另外,mail.server.com 是您的 真实 服务器名称,还是 SO 的占位符? -
占位符。你指的是
-
我建议你输出 $user.mail 的值作为循环体的第一行。只有变量名的行将打印该变量。
标签: windows powershell foreach