Functions/Stop-ProcessSoft.ps1



function Stop-ProcessSoft {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [string] $ProcessName,
        [Parameter()] [switch] $Silent
    )

    if (!(Get-Process $ProcessName -ErrorAction 0)) {
        if (-not($Silent)) {
            Write-Warning "Process $($ProcessName) not found"
        }
    } else {
        1..100 | ForEach-Object {
            $Process = (Get-Process $ProcessName -ErrorAction 0)
            if ($Process) {
                $Process.CloseMainWindow() | Out-Null
            }
        }
    }

}


$scriptblock = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    $ps = Get-Process "$wordToComplete*"
    $ps.Name | ForEach-Object {
        if ($_ -match " ") {
            "'$_'"
        } else {
            $_
        }
    }
}
Register-ArgumentCompleter -CommandName Stop-ProcessSoft -ParameterName ProcessName -ScriptBlock $scriptblock