function processSearch {
Get-Process -Name "$processSearch*"
}
function processKill {
Stop-Process -Name "$processSearch*"
}
$processSearch = Read-Host -Prompt "Enter the full or partial name of the process: "
processSearch
if ((Get-Process -Name "$processSearch*") -eq $null) {
Write-Output "ERROR: NO PROCESS FOUND."
[Threading.Thread]::Sleep(3000)
}
if ((Get-Process -Name "$processSearch*") -ne $null) {
$userInput= Read-Host -Prompt "Kill process?"
}
if ($userInput -eq "y" -or "Y") {
processKill
}
elseif ($userInput -eq "n" -or "N") {
Write-Output "Process not killed."
}
else {
Write-Output "ERROR: UNHANDLED INPUT."
}
When my script gets to $userInput= Read-Host -Prompt "Kill process?", and I enter any text, the script will terminate the selected process.
I'm new to scripting, so please let me know where my logic is flawed, thank you.