PoshCode Archive  Artifact [8669fa3e47]

Artifact 8669fa3e47bed74381edf4ab287ada2903f7a89e2282fc41c63ce7e24431641a:

  • File Kill-Process.ps1 — part of check-in [43812e20dc] at 2018-06-10 14:10:52 on branch trunk — 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. (user: Angel-Keeper size: 1923)

# 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
	}
}
###########################################################################################################
}