#HTML#
$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 40px;border-style: solid;border-color: black;background-color:#white}"
$a = $a + "TD{border-width: 2px;padding: 10px;border-style: solid;border-color: black;background-color:#white}"
$a = $a + "</style>"
$D = "<H>Учетная запись истекает</H>"
#HTML#
$users_seacrh2 = Search-ADAccount -AccountExpiring -TimeSpan "15" -UsersOnly -SearchBase "DC=win13,DC=ru"
$usersget2 = $users_seacrh2 | get-aduser -Properties name,SamAccountName,AccountExpirationDate,description
$usersget2 | foreach {
if ($usersget2 | Where-Object {$_.Manager -eq $null})
{
$report = "C:\1\report.html"
$usersget2 | Where-Object {$_.Manager -eq $null} | select name,SamAccountName,AccountExpirationDate,description | ConvertTo-HTML -head $a,$d | Out-String | out-file $report
$sendEmail = $true
}
$sendEmail = $false
}
if ($sendEmail -eq $true)
{
$bodys = Get-Content -Path $report | Out-String
$encoding = [System.Text.Encoding]::UTF8
Send-MailMessage -From 'AccountExpiring@win13.ru' -To admins@win13.ru -Subject 'Заканчивается срок действия учетной записи' -Body $bodys -BodyAsHtml -SmtpServer 'smtp.servermail.ru' -Encoding $encoding
del $report
}