2
我已经完成了我想用Powershell
发送邮件的命令。这是我的代码使用powershell脚本创建批处理文件
powershell.exe
$user="[email protected]"
$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 '[email protected]' -To '[email protected]' -Subject 'failure Test'
上面的代码工作正常,当我在命令提示符下执行,而不是当我尝试做一个.bat
文件。我用代码做了什么问题?从文件
你得到什么错误? –
当我尝试执行'.bat'文件时,命令提示符打开并执行'poweshell.exe'并停止,像这样的'I:\> powershell.exe Windows PowerShell 版权所有(C)2012 Microsoft Corporation。版权所有。 PS I:\>' – niren
尝试从文件中删除powershell.exe并将其保存为.ps1,然后创建一个.bat文件并写入powershell.exe-文件myscript.ps1 –