我在我的用户创build中添加了一个新的powershell部分,即通过电子邮件向他们的主pipe发送已创build的警报。 但是,由于某种原因,它会将凭证发送给列表中的下一个主pipe,而不是该列中的主pipe,列出的第一个主pipe将获取标头信息。 CSV的构造如下:
1.Lastn | Firstn | 程序| 密码。 | 监
2.Duck | Daffy | …….. 998 | ChangeMe | Bob.Dole
3.Bunny | 巴格斯| ……… 878 | ChangeMe | Elmer.Fudd
脚本是:
$Users = Import-Csv "C:\PSScripts\Create\users.csv" -header("lastname","firstname","program","password","supervisor") foreach ($User in $Users) { $OU = "OU=users,DC=Contoso,DC=local" $UserFirstname = $User.Firstname $UserLastname = $User.LastName $Supervisor = $User.Supervisor $subject = "New Account Creation Completed" $body = "Good Morning! This e-mail is to alert you that your new staff person $SAM has been granted Contoso.org e-mail access. To log in to outlook web application, their username is $SAM and their temporary password is ChangeMe . They will be prompted to change it upon successful login." $smtp = "10.10.1.79" $SAM = $UserFirstname + "." + $UserLastname Send-MailMessage -to [email protected] -Subject $subject -body $body -SmtpServer $smtp -from [email protected] }
但是,主pipeBob.Dole正在通过电子邮件发送“Buggs.Bunny”凭据,而主pipeElmer.Fudd正在通过电子邮件发送“Firstname.Lastname”,这就是$ Sam的构build方式。 所以凭证是上传到主pipe,最后一个主pipe正在通过电子邮件发送'firstname.lastname',而不是一个人。 另外,我收到无法投递的电子邮件,说邮件账号[email protected]是无效的,所以这似乎是误解了一些东西,虽然它执行了命令发送给$ supervisor。 如果我插入一个空白的单元格,在“Supervisor”标题下,监督员列向下移动一个,它向我发出一个错误,指出收件人必须被指定,然后将证书发送到正确的pipe理员,一旦被降档。
问题是,当你在$body中的任务中引用它的时候,你赋值给$body $SAM 。
$Users = Import-Csv "C:\PSScripts\Create\users.csv" -header("lastname","firstname","program","password","supervisor") foreach ($User in $Users) { $OU = "OU=users,DC=Contoso,DC=local" $UserFirstname = $User.Firstname $UserLastname = $User.LastName $Supervisor = $User.Supervisor $subject = "New Account Creation Completed" #moved before $body= .... $SAM ... $SAM = $UserFirstname + "." + $UserLastname $body = "Good Morning! This e-mail is to alert you that your new staff person $SAM has been granted Contoso.org e-mail access. To log in to outlook web application, their username is $SAM and their temporary password is ChangeMe . They will be prompted to change it upon successful login." $smtp = "10.10.1.79" Send-MailMessage -to [email protected] -Subject $subject -body $body -SmtpServer $smtp -from [email protected] }