我已经收集了一个PS脚本,它从一个AD组中获取值,并将它们放在电子邮件中发送到我们的服务台。我遇到的问题是来自AD组的值位于一个数组中,但我不知道如何在不同的行上显示这些值。下面是我使用一个AD组和三个testusers的代码:
$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
发布于 2016-08-25 12:51:05
你做得太过火了。PowerShell喜欢写台词。因为这里已经有了一个数组,所以可以简单地添加到其中。
$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在发送之前,只需将其转换为字符串即可。
Send-MailMessage -Body ($body | Out-String) <OtherParameters>https://stackoverflow.com/questions/39145679
复制相似问题