【问题标题】:How to pull AD user email then pass it to Function to send email using that ADuser email如何提取 AD 用户电子邮件,然后将其传递给 Function 以使用该 ADuser 电子邮件发送电子邮件
【发布时间】: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


【解决方案1】:

试试……

$users = $(Get-ADGroupMember -Identity 'IS-Test-GRP' -Recursive | Select- 
Object -Unique | Get-ADUser -Properties Mail).Mail

我看到的唯一问题是$users 将是对象的集合。当您枚举集合时,我没有看到您指定哪个属性是/具有Mail

【讨论】:

    猜你喜欢
    • 2019-07-04
    • 2016-04-17
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    相关资源
    最近更新 更多