本文介绍了请用PowerShell脚本批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经做了,我想在 Powershell的
发送邮件的命令。这是我的code
I have done the commands that I want to send mail in Powershell
. This is my code
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'
以上code工作正常,当我在命令提示符下执行,而不是当我尝试做一个的.bat
文件。我曾与code做了什么问题?
Above code is working fine when I execute in command prompt, but not When I try to make a .bat
file. What is the problem I have done with code?
推荐答案
从文件中删除powershell.exe并保存为名为.ps1然后创建一个.bat文件,写powershell.exe -file myscript.ps1
Remove powershell.exe from the file and save it as .ps1 then create a .bat file and write powershell.exe -file myscript.ps1
.bat文件:
powershell.exe -file myscript.ps1
myScript.ps1:
myScript.ps1:
$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'
这篇关于请用PowerShell脚本批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!