通过电子邮件发送具有职务的用户

时间:2018-09-07 10:31:28

标签: powershell

我需要一些脚本帮助!因此,脚本的这部分内容将通过电子邮件发送给自己的“职位”字段中有testjob的用户,但是我也需要它通过电子邮件发送给具有该职位的个人用户。如何实现?

#region title check. Get all users which have testjob in their job title
$users = Get-ADUser -Filter {title -like "testjob" -and enabled -eq $true -and name -notlike "random*" -and name -notlike "Dave"} -server server.pri:3268 -pr AccountExpirationDate, accountExpires,department,company
foreach ($user in $users)
{
   if ($user.AccountExpirationDate -eq $null)
   {
       $row = $table.NewRow()
       $row.Name = $user.name
       $row.Department = $user.Department

       $table.Rows.Add($row)

       $arr += @($user.name, $user.Department)
   }
}

#endregion

$body = "The following  accounts do not have a expiry date set.</br></br>"
$body += "Please can someone confirm the end dates for each and add an expiry date to that account.</br></br>"

$body += Convert-DatatablHtml -dt $table
$body += "<br><br>&#128062;"

if ($table.Rows.Count -eq 0)
{
   $body = "All  accounts currently have an end day set.<br><br>&#128062;"
}

Send-Mailmessage -smtpServer "server.local" -from "email@email.com" -to "email@email.com" -subject "Account Expiries" -body $body -bodyasHTML -priority High

我可以按照以下类似的方式添加-$ user吗?

Send-Mailmessage -smtpServer "server.local" -from "email@email.com" -to $user -cc "email@email.com" -subject "Account Expiries" -body $body -bodyasHTML -priority High

0 个答案:

没有答案