From 370e08c2d9d414ae4ed668242b3497982535ea7e Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 5 Jun 2025 07:28:05 +0200 Subject: [PATCH] Added kill-process.ps1 --- scripts/kill-process.ps1 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/kill-process.ps1 diff --git a/scripts/kill-process.ps1 b/scripts/kill-process.ps1 new file mode 100644 index 00000000..a44334e5 --- /dev/null +++ b/scripts/kill-process.ps1 @@ -0,0 +1,35 @@ +<# +.SYNOPSIS + Kills all local processes matching the given name +.DESCRIPTION + ← enter a detailed description of the script here +.PARAMETER + ← enter the description of a parameter here (repeat the .PARAMETER for each parameter) +.EXAMPLE + ← enter a sample command that uses the script, optionally followed by sample output and a description (repeat the .EXAMPLE for each example) +.NOTES + Author: ← enter full name here + License: ← enter license here +.LINK + ← enter URL to additional information here +#> + +[CmdletBinding()] +param( +# [Parameter(Mandatory,ParameterSetName='ByProcessName')] + [string]$ProcessName = $(Read-Host -Prompt 'Enter the process name')) + +function KillProcesses { + Write-Host -BackgroundColor Yellow -ForegroundColor Red "Process to kill: $ProcessName" + Get-Process | Where-Object -FilterScript {$_.processname -eq $ProcessName} | Select-Object id | Stop-Process +} + + +try { + KillProcesses -ProcessName $processName + "✔️ Done." + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}