Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Powershell中激活安全协议_Powershell_Sendmail_Script - Fatal编程技术网

在Powershell中激活安全协议

在Powershell中激活安全协议,powershell,sendmail,script,Powershell,Sendmail,Script,我正在使用powershell生成不同的报告,然后通过邮件发送,但我遇到了下一个异常: Authentication failed because the remote party has closed the transport stream. + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClie nt) [Send-MailMessage], SmtpExcep

我正在使用powershell生成不同的报告,然后通过邮件发送,但我遇到了下一个异常:

    Authentication failed because the remote party has closed the transport stream.
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClie 
   nt) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMe 
   ssage
    + PSComputerName        : localhost
所以,在互联网上查看时,我发现在C中,可以使用下一个代码来解决:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
我想知道如何在Powershell中执行同样的操作

编辑:

多亏了西奥,我得到了这个密码:

$protocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' ; [System.Net.ServicePointManager]::SecurityProtocol = $protocols
但是我还是得到了同样的例外,所以。。。我想知道如何解决这个问题。有些报告在不同的执行过程中随机出现这种情况,有时一切正常,有时又出现这种异常情况。

好的,我得到了我的答案:

我发送电子邮件的脚本是:

Start-Job -ScriptBlock {
    Send-MailMessage -To $($args[0]) -From $($args[1]) -Subject $($args[2]) -Body $($args[3]) -SmtpServer $($args[4]) -UseSsl -Port "25" -Credential $($args[6]) -Attachments $($args[5]) 
    } -ArgumentList $To, $From, $Subject, $Body, $SMTP, $DestinationExcelFilePath, $mycreds | Wait-Job | Receive-Job
现在是:

Start-Job -ScriptBlock {
    $protocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' ; [System.Net.ServicePointManager]::SecurityProtocol = $protocols
        Send-MailMessage -To $($args[0]) -From $($args[1]) -Subject $($args[2]) -Body $($args[3]) -SmtpServer $($args[4]) -UseSsl -Port "25" -Credential $($args[6]) -Attachments $($args[5]) 
    } -ArgumentList $To, $From, $Subject, $Body, $SMTP, $DestinationExcelFilePath, $mycreds | Wait-Job | Receive-Job

$protocols=[System.Net.SecurityProtocolType]'Ssl3、Tls、Tls11、Tls12';[System.Net.ServicePointManager]::SecurityProtocol=$protocolsNice!但是我得到了同样的例外。。。悲哀的