首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单独行的电子邮件正文中的数组值

在单独行的电子邮件正文中的数组值
EN

Stack Overflow用户
提问于 2016-08-25 12:43:42
回答 1查看 1.1K关注 0票数 0

我已经收集了一个PS脚本,它从一个AD组中获取值,并将它们放在电子邮件中发送到我们的服务台。我遇到的问题是来自AD组的值位于一个数组中,但我不知道如何在不同的行上显示这些值。下面是我使用一个AD组和三个testusers的代码:

代码语言:javascript
复制
$members = @(Get-qADGroupMember adgroup -IncludedProperties "DisplayName,sAMAccountName")
$smtp = "smtpserver.domain.com" 
$to = "helpdesk@domain.com"
$from = "security@domain.com"
$subject = "Accounts Disabled"
$body = "Helpdesk, `n `n"
$body += "These users have had their passwords reset and their accounts disabled. There is no action required on the part of IT helpdesk, this is strictly to notify you.  These users will probably be calling soon: `n `n"

$body += For ($i=0; $i -lt $members.Length; $i++) {
    $members[$i -join "`n"]
}

$body += "`n"
$body += "For any questions regarding this, please contact the Information Security Team  `n `n"
$body += "Thank you `n"
$body += "Information Security"

这是输出:

帮助台, 这些用户已经重置了密码和帐户。IT服务台不需要采取任何行动,这是严格通知您的。这些用户可能很快就会打电话来: 域\testuser3 1域\testuser3 2域\testuser3 3关于这方面的任何问题,请与信息安全小组联系谢谢信息安全

如何才能让来自该组的用户在他们自己的行上像这样显示呢?

域\testuser1 1 域\testuser2 2 域\testuser3 3

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-25 12:51:05

你做得太过火了。PowerShell喜欢写台词。因为这里已经有了一个数组,所以可以简单地添加到其中。

代码语言:javascript
复制
$body = @("Helpdesk,") 
$body += "These users have had their passwords reset and their accounts disabled. There is no action required on the part of IT helpdesk, this is strictly to notify you. These users will probably be calling soon:"

$body += $members

在发送之前,只需将其转换为字符串即可。

代码语言:javascript
复制
Send-MailMessage -Body ($body | Out-String) <OtherParameters>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39145679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档