Search code examples
windowspowershellbatch-filecmd

how to do taskkill for all programs in the folder using cmd / powershell


I want to do Taskkill for all programs ending with exe in a folder with cmd / powershell

Example

taskkill /f /im C:\folder\*.exe

Solution

  • In PowerShell, something like this:

    $files = gci "C:\Path\To\Files" -Filter "*.exe"
    
    foreach($file in $files){
        Get-Process | 
        Where-Object {$_.Path -eq $file.FullName} | 
        Stop-Process -WhatIf
    }
    

    Remove the -WhatIf when you're confident that the correct processes would be stopped.