2

我已经完成了要发送邮件的命令Powershell。这是我的代码

powershell.exe
$user="username@gamil.com"
$pass=cat I:\password.txt | convertto-securestring
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $pass
send-MailMessage -SmtpServer smtp.gmail.com -Credential $mycred -Usessl true -From 'username@gamil.com' -To 'usernametwo@gamil.com' -Subject 'failure Test'

当我在命令提示符下执行时,上面的代码工作正常,但当我尝试创建.bat文件时却不行。我用代码做了什么问题?

4

1 回答 1

5

从文件中删除 powershell.exe 并将其保存为 .ps1 然后创建一个 .bat 文件并写入 powershell.exe -file myscript.ps1

蝙蝠档案:

powershell.exe -file myscript.ps1

myScript.ps1:

$user="username@gamil.com"
$pass=cat I:\password.txt | convertto-securestring
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $pass
send-MailMessage -SmtpServer smtp.gmail.com -Credential $mycred -Usessl true -From 'username@gamil.com' -To 'usernametwo@gamil.com' -Subject 'failure Test'
于 2013-09-26T10:41:34.800 回答