我想要在一个文件和一个文件中计算进程数如果计数小于特定数量,那么它将生成一封邮件。
这是我的代码:
--@echo off
cd /
:start
tasklist |find "svchost.exe" >process.txt
SET /P V1=| findstr /R /N "^" process.txt|find /C":"
IF "%V1%"=="12" (GOTO :start ) ELSE
(Send-MailMessage -to "sender_id" -from "PowerShell <receipient_id>" -Subject "Test" -body "Test for Send-MailMessage")
pause
答案 0 :(得分:0)
if((get-process 'svchost').Count -lt 12)
{
Send-MailMessage -to "sender_id" -from "PowerShell <receipient_id>" -Subject "Test" -body "Test for Send-MailMessage" -SMTPServer 'mail.something.com'
}
答案 1 :(得分:0)
大多数cmd
命令比你想象的更强大:
:start
timeout 1 :: wait cycle to reduce cpu workload
for /f %%i in ('tasklist^|find /c "svchost.exe"') do set /a count=%%i
if %count% geq 12 goto :start
echo count is less than 12