mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-19 19:27:52 +02:00
Added kill-process.ps1
This commit is contained in:
parent
0eb30f5c64
commit
370e08c2d9
35
scripts/kill-process.ps1
Normal file
35
scripts/kill-process.ps1
Normal file
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user