0

I have created the below script that what it does is to kill a specific Veeam process related to a job name. The issue is that it have to first find the the job id, then search in processes description for that ID and kill it. But i think somehow is making a infinite loop that in some cases when i have to run it multiple times (because there could be more than one process related to the ID), it reboots the server.

$JobName = Read-Host "Enter Job name"
$JobID = Get-VBRJob | select name, ID | Where {$_.name -like $JobName} | select -expand ID
wmic Path win32_process Where "CommandLine Like '%$JobID%'" Call Terminate
Crit Scratch
  • 43
  • 1
  • 10
  • I kind of shiver seeing stuff along the lines of `$_.Name -like ` and `"CommandLine Like '%%'` when it's about terminating something. Is it impossible to know the exact value of something in any of the steps? Some sort of validation of what you have in `$JobID` would seem mandatory to me. If it's empty you just might call terminate on ALL processes. – notjustme Mar 03 '20 at 14:45
  • Sounds logic. Yep. How can i set like mandatory to have an input?. In other hand, maybe i can first call for a list of jobs and select the one that is named as the input?. – Crit Scratch Mar 03 '20 at 14:59
  • I'm not familiar with the (any) Veeam PS-module but wouldn't `Get-VBRJob -Name ""` get the one desired (assuming it's known by name) job and only that one job? If you somehow must run the `where`-clause anyway, try changing the matching to something like `| where { $_.Name -eq $JobName }` instead. – notjustme Mar 03 '20 at 15:03

0 Answers0