以下のコードでは、エラーレベル チェックは機能しません。そのため、障害が発生した場合、メールは送信されません。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'"
)