-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_kill.ps1
82 lines (65 loc) · 2.72 KB
/
search_kill.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#----------------------------------------------
#<Script name> was created by <Name> <Surname>
#<Script definition>
#----------------------------------------------
#----------------------------------------------
#--------------------Fields--------------------
#----------------------------------------------
#----------------------------------------------
#--------------------Functions-----------------
#----------------------------------------------
Function GetProcess($option) {
$errorValue = 1;
try {
if($option -eq 1) {
$processName = Read-Host "Please enter process name"
Get-Process $processName -ErrorAction Stop
}
}
catch {
Write-Host "The process you entered doesn't exist" -foregroundcolor "Red" "`r`n"
Write-Host "Available process name list (running):" -foregroundcolor "Green"
Get-Process | Select-Object Name | Format-Wide -Column 5
$errorValue = 0;
}
#if process found kill by name
if(($errorValue -ne 0) -and ($option -eq 1)) {
Write-Host "*If you want to kill the process press 1*"
Write-Host "*To exit press 0*"
$optionKill = Read-Host "Your option"
if($optionKill -eq 1){
Stop-Process -Name "$processName"
Write-Host "Process $processName successfully killed" -ForegroundColor "Green"
}
}
#------------------------------------------------------------------------------------------#
try {
if($option -eq 2) {
$processId = Read-Host "Please enter process Id"
Get-Process -Id $processId -ErrorAction Stop
}
elseif(($option -ne 1) -and ($option -ne 2)) {
Write-Host "Invalid number"
}
}
catch {
Write-Host "The process Id you entered doesn't exist" -ForegroundColor "Red" "`r`n"
Write-Host "Available process Id list (running):" -foregroundcolor "Green"
Get-Process | Select-Object Id | Format-Wide -Column 5
$errorValue = 0;
}
#if process found kill by id
if(($errorValue -ne 0) -and ($option -eq 2)) {
Write-Host "*If you want to kill the process press 1*"
Write-Host "*To exit press 0*"
$optionKill = Read-Host "Your option"
if($optionKill -eq 1) {
Stop-Process -Id $processId
$processNameFromId = Get-Process -Id $processId | Select-Object Name
Write-Host "Process $processNameFromId successfully killed" -ForegroundColor "Green"
}
}
}
#----------------------------------------------
#-------------------Execution code-------------
#----------------------------------------------