【发布时间】:2018-08-09 08:44:46
【问题描述】:
我希望改进旧的批处理脚本并将其升级到 powershell,这是一个 robocopy 批处理脚本,我希望它在完成后发送带有日志文件的邮件。我设法对驱动器映射和 robocopy 部分进行了排序,但我在让 send-mailmessage 部分工作时遇到了一些问题
`$SourceFolder = "V:\"
$DestinationFolder = "Y:\"
$Dateandtime = Get-Date -format filedate
$password = XXXXXXXXX
$Subject = "Robocopy Results: Backup USA - NL"
$SMTPServer = "mailserver.domain.com"
$Sender = "backupusr@domain.com"
$Username = "backupusr"
$Recipients = "administrator@domain.com"
$Admin = "administrator@domain.com"
$SendEmail = $True
$IncludeAdmin = $True
$AsAttachment = $False
$Cred = new-object Management.Automation.PSCredential $Username, ($password
| ConvertTo-SecureString -AsPlainText -Force)`
这是导致脚本超时的行
Send-MailMessage -SmtpServer $SMTPServer -From $Sender -To $Recipients -Subject $Subject -Body "Robocopy results are attached." -DeliveryNotificationOption onFailure -UseSsl -Credential $Cred
这是我收到的错误
Send-MailMessage :操作已超时。 在 C:\Scripts\bpcti-robocopy.ps1:113 char:1 + Send-MailMessage -SmtpServer $SMTPServer -From $Sender -To $Recipient ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
任何帮助将不胜感激。
【问题讨论】:
-
快速编辑:我设法让命令在没有密码的情况下工作(我必须手动输入)
Send-MailMessage -SmtpServer mailserver.domain.com - From backupusr@domain.com -To administrator@domain.com - Subject testing -Body "Robocopy results are attached." - DeliveryNotificationOption onFailure -Credential "backupusr@domain.com"我现在的问题是我使用什么语法来添加密码
标签: powershell