我想从安全组获取所有用户并提取其电子邮件。收到他们的电子邮件后,我想将该电子邮件地址列表传递给一个函数(最好是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'
}
答案 0 :(得分:1)
尝试...
$users = $(Get-ADGroupMember -Identity 'IS-Test-GRP' -Recursive | Select-
Object -Unique | Get-ADUser -Properties Mail).Mail
我看到的唯一问题是$users
将是对象的集合。当您枚举集合时,我看不到您指定哪个属性是/具有Mail
。