Functions/Stop-ProcessSoft.ps1


function Stop-ProcessSoft {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ArgumentCompleter( {
                param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters )
                Get-Process "$wordToComplete*" | ForEach-Object { $_.Name } }
        )]
        [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 }
        }
    }

}