Skip to content

Commit 370e08c

Browse files
author
Markus Fleschutz
committed
Added kill-process.ps1
1 parent 0eb30f5 commit 370e08c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

scripts/kill-process.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<#
2+
.SYNOPSIS
3+
Kills all local processes matching the given name
4+
.DESCRIPTION
5+
← enter a detailed description of the script here
6+
.PARAMETER
7+
← enter the description of a parameter here (repeat the .PARAMETER for each parameter)
8+
.EXAMPLE
9+
← enter a sample command that uses the script, optionally followed by sample output and a description (repeat the .EXAMPLE for each example)
10+
.NOTES
11+
Author: ← enter full name here
12+
License: ← enter license here
13+
.LINK
14+
← enter URL to additional information here
15+
#>
16+
17+
[CmdletBinding()]
18+
param(
19+
# [Parameter(Mandatory,ParameterSetName='ByProcessName')]
20+
[string]$ProcessName = $(Read-Host -Prompt 'Enter the process name'))
21+
22+
function KillProcesses {
23+
Write-Host -BackgroundColor Yellow -ForegroundColor Red "Process to kill: $ProcessName"
24+
Get-Process | Where-Object -FilterScript {$_.processname -eq $ProcessName} | Select-Object id | Stop-Process
25+
}
26+
27+
28+
try {
29+
KillProcesses -ProcessName $processName
30+
"✔️ Done."
31+
exit 0 # success
32+
} catch {
33+
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
34+
exit 1
35+
}

0 commit comments

Comments
 (0)