Public/Tasks/Invoke-KillProcessTask.ps1

#Requires -Modules WebAdministration

Set-StrictMode -Version Latest



Function Invoke-KillProcessTask {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
        [Parameter(Mandatory=$true)]
        [int]$processId
    )

    $message = "Killing process id: $processId"
    if ($PSCmdLet.ShouldProcess("$processId", "$message" )) {
        Write-TaskInfo $message -Tag 'KillProcess'
        try {
            Stop-Process -id $processId -Force -Confirm:$false
        } catch {
            Write-Warning $_.Exception.Message
        }
    }

}
Register-SitecoreInstallExtension -Command Invoke-KillProcessTask -As KillProcess -Type Task -Force