Hi all,
I am new to powershell and I am looking to write a script that will check if a service is not started and will start the service and if it is started will confirm that it is started in a log and or display. I found a script online that seems to be working, it will start the service if it is not equal to started. However I can't get it to confirm that if it is already started to display this (and not sure how exactly to input into log yet)
I am experimenting with the telnet service on a windows 2008 server
See below copy of script, no matter if the service is started or not it will display the same text that "service is now started" etc. Is there a better way of doing this as i can't seem to get mutiple if statements working?
Thank you for your help
function FuncCheckService{
param($ServiceName)
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "Started"){
Start-Service $ServiceName
Write-Host "Starting " $ServiceName " service"
" ---------------------- "
" Service is now started"
}
if ($arrService.Status -eq "started"){
Write-Host $ServiceName " service is already started"
}
}
FuncCheckService -ServiceName "Telnet"