请参阅下文。无论出于何种原因,我都无法在运行的.exe进程上杀死任何人。我随机看到了这个脚本,这就是为什么我认为还有其他事情发生的原因。
我所看到的是,整个脚本在测试时都可以正常工作,但随后我推广以证明它只是触发了电子邮件部分。电子邮件部分没问题。
此代码将确保即使挂起进程也能杀死它们。
$process = Get-Process -Name "IVR1","IVR2","IVR3"
$IVR1path = "C:\IVR1"
$IVR2path = "C:\IVR2"
$IVR3path = "C:\IVR3"
Get-Process $process -ErrorAction SilentlyContinue
if ($process) {
Get-Process -Name $process | kill -PassThru
Start-Sleep -s 5
cd $IVR1path
Start-Process ".\IVR1.exe"
cd IVR2path
Start-Process ".\IVR2.exe"
cd IVR3path
Start-Process ".\IVR3.exe"
cd ..
cd ..
$From = "IVR1@example.com.au"
$To = "myemail@example.com.au"
$cc = "myemail@example.com.au"
$Subject = "**TEST** - IVR1 has been recovered"
$Body = "The IVR has been successfully recovered"
$SMTPServer = "mail.example.com.au"
Send-MailMessage -From $From -to $To -cc $cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer
}
答案 0 :(得分:0)
使用以下代码。
$process = "IVR1","IVR2","IVR3" #Creates array of process names
$IVR1path = "C:\IVR1"
$IVR2path = "C:\IVR2"
$IVR3path = "C:\IVR3"
if ($process) {
Get-Process -Name $process | kill -PassThru
Start-Sleep -s 5
Start-Process "$IVR1path\IVR1.exe"
Start-Process "$IVR2path\IVR2.exe"
Start-Process "$IVR3path\IVR3.exe"
$From = "IVR1@example.com.au"
$To = "myemail@example.com.au"
$cc = "myemail@example.com.au"
$Subject = "**TEST** - IVR1 has been recovered"
$Body = "The IVR has been successfully recovered"
$SMTPServer = "mail.example.com.au"
Send-MailMessage -From $From -to $To -cc $cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer
}