Powershell can’t kill process, saying “There are no running instance of the task” but Task Manager or WMIC can kill process. Why?

I’ve got a situation with a process spawned by MS SQL Server via XP_CMDShell .
XP_CMDShell is calling a PowerShell script, which then calls an executable to run an automated report.

I’m doing this so Powershell can kill the process if the executable hangs/takes too long for any reason.

This is working in general, but this morning I found a number of surviving processes of the executable that hadn’t died.

This process turned out to not be killable using either Powershell, or Taskkill from an Admin command prompt.
It was killable from WMIC or Task Manager.

Can anyone help me understand why? I’d rather have some chance of figuring out why it’s not killing cleanly.

Process followed:

Was expecting the Powershell scripting to kill the process successfully.

The relevant part of the PowerShell scripting that’s being used to kill this executable when it hangs:

$proc = Start-Process -FilePath $Executable -ArgumentList $Arguments -PassThru
   Write-host $proc.id
   Start-Sleep -seconds $MemcheckInterval  #Give the process 2 seconds to start up and use memory
   Write-host $proc.WorkingSet       
   $StaticCycles=0
   $ProcessState="Working State"     #Assume that the state is working ok
   $Cycles=1                         #Start the count of mem check cycles
   $MemcheckValue=$proc.WorkingSet   #Get the current working memory value  
   While((-not $proc.HasExited) -and ($Cycles -lt $MaxCycles) -and ($StaticCycles-lt $MaxStaticCycles) -and ((Get-Date)-lt $MaxTimeout))
      {  
       Start-Sleep -seconds $MemcheckInterval 
       $Cycles=$Cycles+1
       if (($MemcheckValue=$proc.WorkingSet) -and ($proc.WorkingSet-ne 0)) 
          {$ProcessState="Static State"
           $StaticCycles=$StaticCycles+1
           }
       Else {$ProcessState="Working State"}
      }
   Write-host $Cycles
   Write-host $ProcessState
   Write-host $proc.TotalProcessorTime
   Write-host ((Get-Date)-$proc.StartTime)
   write-host ($MaxTimeout)
   if($proc.HasExited ) {
   #Success
   #Write-host "Detected Process already closed."
   return 'Successful'
   }
   else {
   #Failure
   #Write-Host "Detected Process still running."
   #Write-Host "Check for and kill process."
   Write-host $proc.WorkingSet
   $proc | Stop-Process -PassThru -Force -ErrorAction SilentlyContinue | Out-Null
   return 'Timed Out'
   }

Fine, so we got the ProcessID from Task Manager, and tried killing them:

First via Powershell:
Stop-Process 13636 -Force
This doesn’t work, and provides no useful information.

Then via an Administrator Command Prompt:
taskkill /F / PID 13636

This also didn’t work, but now we got an error:

ERROR: The process with PID 13636 could not be terminated.
Reason: There is no running instance of the task.

Except the task/process is visible from Task Manager.

Task Manager can kill the process via Right click End Task
WMIC can also kill the process from the same administrator command prompt we used previously using the command:
WMIC process where processid="13636" call terminate

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật