在下面的代码中,错误级别检查永远不会起作用。因此,如果发生故障,则不会发出任何电子邮件。Powershell 命令是正确的,并且在此构造之外工作。我也试过直接检查: If %ERRORLEVEL% NEQ 0
但这也行不通。
有任何想法吗?谢谢!
@echo off
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "dt=%mm%-%dd%-%yyyy%"
"LogParser.exe" "SELECT * INTO tblIisLog FROM \\iislogs\%dt%\*.log" -i:iisw3c -o:SQL - oConnString:"Driver=SQL Server;Server=servername; Database=IISDB;Trusted_Connection=yes" - createTable:ON
SET /a RC=%ERRORLEVEL%
IF %RC% NEQ 0
(
powershell.exe -executionpolicy unrestricted -command "send-mailmessage -from 'me@abc.com' -to 'me@abc.com' -subject 'test' -body 'testing' -smtpServer 'smtpserv.com'"
)