I need a script that will ask a user to input any service name and the script will check if the script is available (doesn’t matter running or stopped as long as its available in windows)
if it is available it will write “The service exists!” in green color
If it doesn’t exist
it will write “the service does not exist!” in red letters
Please help me Im trying for hours with no success!
I need a script that will ask a user to input any service name and the script will check if the service is available (doesn’t matter running or stopped as long as its available in windows)
if it is available it will write “The service exists!” in green color
If it doesn’t exist
it will write “the service does not exist!” in red letters
I found this link aswell but it doesn’t help me since this script searchs for 1 service “alg”
I want the script to check any service the user will input
I don’t know how to fix this script in order to do it… if u could do it for me it will be great.
$serviceName = Read-Host "Please enter service name"
If (Get-Service $serviceName -ErrorAction SilentlyContinue) {
If ((Get-Service $serviceName).Status -eq 'Running') {
Write-Host "$serviceName found, and is running" -ForegroundColor Green
} Else {
Write-Host "$serviceName found, but it is not running." -ForegroundColor Yellow
}
} Else {
Write-Host "$serviceName not found" -ForegroundColor Red
}
$s=Get-Service
$name= read-Host "enter a service name"
foreach($s2 in $s.name)
{
if($s2 -like $name)
{
Write-Host "service exist" -ForegroundColor green
exit
}
}
Write-Host "service no exist" -ForegroundColor red