This is part of a larger script but, I feel like this part could be streamlined a bit. The code currently works but I feel like doing a Get-Process
call twice is inefficient. Am I wrong?
# Variables:
$ServiceNames = @("HealthTLService","ThreatLockerService")
# Stop & disable some services - if they're running
ForEach ($Service in $ServiceNames) {
Get-Service | Where-Object {($_.Name -eq $Service)} | Stop-Service -Force -ErrorAction SilentlyContinue -Verbose
Get-Service | Where-Object {($_.Name -eq $Service)} | Set-Service -StartupType Disabled -ErrorAction SilentlyContinue -Verbose
}
```