<commit_before>﻿<#
.NOTES
Copyright 2012 <NAME>
Licensed under the Apache License, Version 2.0 (the "License");
http://sushihangover.blogspot.com
.SYNOPSIS
Kill process by name
.DESCRIPTION
This scripts provides a way to kill processes by name verus by Id
.EXAMPLE
Do-KillByName.ps1 bonjour
.LINK
http://sushihangover.blogspot.com
#>
$pName = $args[0]
$killList = get-process | where {($_.Name -eq $pName)}
If ($killList -ne $null) {
    $killList
    $killList | foreach { $_.Kill() }
} Else {
    echo "No processes found"
}<commit_msg>Updated this script to handle pipelining the input and output, see examples in script...<commit_after>﻿<#
.NOTES
Copyright 2012 <NAME>
Licensed under the Apache License, Version 2.0 (the "License");
http://sushihangover.blogspot.com
.SYNOPSIS
Kill process by name
.DESCRIPTION
This scripts provides a way to kill processes by name vs. Id
Do-KillByName.ps1 bonjour -whatif
.EXAMPLE
Do-KillByName.ps1 notepad
.EXAMPLE
Get-Process | Do-KillByName.ps1 -whatif | ft -AutoSize
.EXAMPLE
gwmi win32_process | where {$_.getowner().user -eq $env:username} | select handle | % { get-process -id $_.handle } | Do-killbyName -whatif
Kill all the processes that the current user is running (this includes the powershell console that is running this oneliner!!)
.LINK
http://sushihangover.blogspot.com
#>
[CmdletBinding()] 
Param(
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$processName, 
    [Parameter(Mandatory=$false)][switch]$whatif
    )
Begin {
    $killList = @()
}
Process {
    if ($_ -is [System.Diagnostics.Process]) {
        $killMe = $_
    } else {
        $killMe = get-process | where {($_.Name -eq $processName)}
    }
    try {
        if ($killMe -is [System.Diagnostics.Process]) {
            $killList += $killMe
            if (!$whatif.IsPresent) {
                # $killMe.Kill()
            }
        }
    } catch {
        write-host "No process named $processName found" -ForegroundColor Red -BackgroundColor White
    }
}
End {
    return $killList
}
{'fraction_non_alphanumeric': 0.12432165762210162, 'fraction_numerical': 0.009373458312777503, 'mean_word_length': 3.342612419700214, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5349065', 'n_tokens_mistral': 681, 'n_tokens_neox': 652, 'n_words': 196}