powershell send-message带有正文文本不使用批处理脚本
需要帮助转换powershell命令以批量运行。我可以得到以下操作正常为.ps1:
$filecontent = Get-Content -path C:\temp\status.txt | Out-string
Send-MailMessage -to "[email protected]" -from "[email protected]" -subject "STATUS: PASS" -body "$filecontent" -smtpServer mail2.co.test.ca.us
当我将其放入批处理时:
PowerShell -command "$filecontent = Get-Content -path C:\temp\status.txt | Out-String" ^
Powershell -command Send-MailMessage ^
-to \"[email protected]\" ^
-from \"[email protected]\" ^
-subject \"STATUS: PASS \" ^
-body \"$filecontent\" ^
-smtpServer mail2.co.test.ca.us
我会得到此错误:
外串:找不到一个位置参数接受参数“ send-mablemessage”。 在线:1个字符:55 + ... tatus.txt |外串发送sendmailMessage -to“ “ ... + categoryInfo:invalidargument :( :) [out-string],parameterBindingException + flutlqualifyErrid:positionalParameternotfound,Microsoft.powershell.commands.outstringcommand
在批处理中进行这项工作的唯一方法是将原始的powershell语法放入.ps1中并从批处理中调用它?发送邮件部分工作正常。尝试了$ filecontent Line,没有“和-raw”而不是管道和串线。
Need help converting PowerShell commands to run in batch. I can get the following to run fine as .ps1:
$filecontent = Get-Content -path C:\temp\status.txt | Out-string
Send-MailMessage -to "[email protected]" -from "[email protected]" -subject "STATUS: PASS" -body "$filecontent" -smtpServer mail2.co.test.ca.us
When I put it into a batch:
PowerShell -command "$filecontent = Get-Content -path C:\temp\status.txt | Out-String" ^
Powershell -command Send-MailMessage ^
-to \"[email protected]\" ^
-from \"[email protected]\" ^
-subject \"STATUS: PASS \" ^
-body \"$filecontent\" ^
-smtpServer mail2.co.test.ca.us
I get this error:
Out-String : A positional parameter cannot be found that accepts argument 'Send-MailMessage'. At line:1 char:55 + ... tatus.txt | Out-String Send-MailMessage -to "[email protected]" -from " ... + CategoryInfo : InvalidArgument: (:) [Out-String], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.OutStringCommand
Is the only way to make this work in a batch is to put the original PowerShell syntax into a .ps1 and call it from the batch? The send-mail portion works fine. Tried the $filecontent line without " and -Raw instead of the pipe and Out-string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试将其放入一个命令中:
因为在第二个命令
$ filecontent
不再存在。You should try to put it in one command :
Because in the second command
$filecontent
no longer exist.