每种语言的passwordLastSet和password即将过期,然后发送电子邮件

时间:2018-07-22 15:20:46

标签: powershell exchange-server

今天我的想法是提取一些密码过期的用户,然后以每种语言发送电子邮件。

 $files=(Get-ChildItem "$HOME\script\expire\").FullName
    $send=@{
    to = "administrator@corp.internal"
    from = "administrator@corp.internal"
    Subject = "US" 
    Attachment = $files
    SmtpServer = "10.10.10.10"
    }

    $French=@{
    to = "administrator@corp.internal"
    from = "administrator@corp.internal"
    Subject = "FR"
    Attachments = $files
    SmtpServer = "10.10.10.10"}

    $AU=@{
    to = "administrator@corp.internal"
    from = "administrator@corp.internal"
    Subject = "AU"
    Attachments = $files
    SmtpServer = "10.10.10.10"}

    Get-AdUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and PasswordLastSet -gt 0 } -Verbose -Properties DisplayName, PasswordLastSet, Mail, Office -SearchBase "OU=Test,OU=CORP,DC=corp,DC=internal" -Server "10.10.10.1" | Where-Object {
            $_.PasswordLastSet.AddDays(30).Date -eq ((Get-Date).AddDays(30).Date)
        }  |ForEach-Object -Verbose {


    $bodyreset=
    @"
    I delete real message because it was to big and I don't have any issue to receive these mail
    "@

        if ( $_.office -like "FR*")
        {
       Send-MailMessage -Body "$bodyreset"  -BodyAsHtml @french
       }elseif($_.office -like "US*")
       {
       Send-MailMessage -Body "$bodyreset"  -BodyAsHtml  @send
       }
       else{
      Send-MailMessage -Body "$bodyreset"  -BodyAsHtml @AU
        }
     }

我在虚拟服务器上拥有29000个用户,并且该用户是在同一天创建的。

我正在寻求帮助,以了解该脚本为什么不发送29 000电子邮件,实际上我收到了大约14000电子邮件。

在同一地址发送了14885封邮件后,我可以看到此错误。

Send-MailMessage : Service not available, closing transmission channel. The server response was: 4.4.1 Connection timed out
At line:82 char:3
+   Send-MailMessage -Body "$bodyreset"  -BodyAsHtml @AU
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

Send-MailMessage : Service not available, closing transmission channel. The server response was: 4.4.1 Connection timed out
At line:82 char:3
+   Send-MailMessage -Body "$bodyreset"  -BodyAsHtml @AU
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

我尝试导出CSV文件,可以看到29000个用户,谢谢.count

您能帮我理解我哪里错了。

0 个答案:

没有答案