Import-Module ActiveDirectory
$month3 = (Get-Date).AddMonths(-3)
$month1 = (Get-Date).AddMonths(-1)
$emailattachment1 = "C:\tasks\users_created_last_3month\users_last_3_month.csv"
$emailattachment2 = "C:\tasks\users_created_last_3month\users_last_1_month.csv"
$users3 = Get-ADUser -filter * -property * | ?{$_.Created -gt $month3} | select name,samaccountname,created,mail,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}|?{$_.Disabled -eq 0} | select name,samaccountname,created,mail | Export-Csv $emailattachment1 -Delimiter ";" -NoTypeInformation -Encoding Default
$users1 = Get-ADUser -filter * -property * | ?{$_.Created -gt $month1} | select name,samaccountname,created,mail,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}}|?{$_.Disabled -eq 0} | select name,samaccountname,created,mail | Export-Csv $emailattachment2 -Delimiter ";" -NoTypeInformation -Encoding Default
$EmailFrom = ""
#$EmailTo = ""
$EmailTo = ""
$EmailSubject = "Список пользователей от " + (Get-Date).GetDateTimeFormats("u")
$emailbody = $EmailSubject
$SMTPServer = ""
#$SMTPAuthUsername = ""
#$SMTPAuthPassword = ""
#function send_email {
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($emailfrom)
$mailmessage.To.add($emailto)
$mailmessage.Subject = $emailsubject
$mailmessage.Body = $emailbody
$attachment1 = New-Object System.Net.Mail.Attachment($emailattachment1, 'text/plain')
$attachment2 = New-Object System.Net.Mail.Attachment($emailattachment2, 'text/plain')
$mailmessage.Attachments.Add($attachment1)
$mailmessage.Attachments.Add($attachment2)
#$mailmessage.IsBodyHTML = $true
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
# $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("$SMTPAuthUsername", "$SMTPAuthPassword")
$SMTPClient.Send($mailmessage)
#}
#del $emailattachment1
#del $emailattachment2