# encoding: ascii
# api: powershell
# title: Kill-Process
# description: The script is intended for process end on any computer in a local area network. Class WMI is used. The rights of the manager to the local area network computer are necessary.
# version: 0.1
# type: function
# author: Angel-Keeper
# license: CC0
# function: Kill-Process
# x-poshcode-id: 6224
# x-archived: 2016-04-14T06:19:53
# x-published: 2016-02-19T06:01:00
#
#
function Kill-Process() {
param(
[string[]]$ComputerNames,
[string[]]$ProcessNames,
$User
)
###########################################################################################################
if ($ProcessNames -eq $null) {Write-Error 'The parametre "ProcessNames" cannot be empty';break}
###########################################################################################################
if ($User -is [String]) {
	$Connection = Get-Credential -Credential $User
	}
###########################################################################################################
foreach ($int1 in $ComputerNames){
	foreach ($int2 in $ProcessNames) {
		if ($int2 -notlike "*.exe") {$int2 = $int2 + '.exe'}
			if ($Connection -eq $null) {$count = 0
				$Process_Kill = gwmi "win32_process"  -ComputerName $int1 -filter "name='$int2'" | 
								ForEach-Object {$_.terminate();$count++}					
				$Process_Kill = "" | select @{e={$int1};n='Computer'},`
											@{e={$int2};n='Process'}, @{e={$count};n='Count'}
			}
			else {$count = 0
				$Process_Kill = gwmi "win32_process"  -ComputerName $int1 -filter "name='$int2'" | 
								ForEach-Object {$_.terminate();$count++}
				$Process_Kill = "" | select @{e={$int1};n='Computer'},`
											@{e={$int2};n='Process'}, @{e={$count};n='Count'}
			}
	$Process_Kill
	}
}
###########################################################################################################
}
