我錯過了某些東西,當我嘗試將下面的單行命令轉換爲多行時。我搜索,發現並試圖在Powershell -Command over multiple line錯誤引用和/或轉義,cmd運行Powershell
之後建模此更改我缺少什麼?我試圖讓測試變得很容易。只需將前兩(2)行更改爲適合您系統的內容即可。
=== emailtest.bat
@ECHO OFF
SET "[email protected]"
SET "SMTPHOST=imr2.nowhere.org"
SET "FN=C:\Windows\win.ini"
@ECHO ON
powershell -Command "& send-mailmessage -to "%RECIPIENT%" -from '[email protected]' -subject 'test file transfer' -SmtpServer '%SMTPHOST%' -BodyAsHTML 'The file is <a href="%FN">here</a> for you.'
powershell -noprofile -Command "&{"^
send-mailmessage -to "%RECIPIENT%"^
-from '[email protected]'^
-subject 'test file transfer'^
-SmtpServer '%SMTPHOST%'^
-BodyAsHTML 'The file is <a href="%FN%">here</a> for you.'^
"}"
===輸出是
C:>call emailtest.bat
12:17:24.75 C:\Users\me\t
C:>powershell -Command "& send-mailmessage -to "[email protected]" -from '[email protected]' -subject 'test file transfer' -SmtpServer 'imr2.nowhere.org' -BodyAsHTML 'The file is <a href="C:\Windows\win.ini">here</a> for you.'
12:17:27.28 C:\Users\me\t
C:>powershell -noprofile -Command "&{" send-mailmessage -to "[email protected]" -from '[email protected]' -subject 'test file transfer' -SmtpServer 'imr2.nowhere.org' -BodyAsHTML 'The file is href="C:\Windows\win.ini""}" 0</a 1>for
The system cannot find the file specified.
如果您直接使用PowerShell而不是嘗試在cmd.exe外殼腳本(批處理文件)中打包PowerShell命令,事情會變得更簡單和更簡單。 –