BES Service stop process via PowerShell

I have a script which suppose to stop BES Services in correct order during service recycle process. Sometime when I stop service via Windows Service GUI one of services for eg. Web Reports service hangs in stopping status and nothing happens. I prepare the script to wait 15 seconds when service is in stopping and then kill it. My question is : does this kind of kill action after 15 seconds when a service is in stopping status may brake sth. or cause some BFEnterprise database issue ?? it can be that after 16 seconds the service will stop working without killing. When I kill the WebReports service during his interaction with SQL Database, can I make some damage ?? Please find the code below:

Function Stop_BESServices {

#variable services while stop

#stop BES services by calling the win32_process class to prevent the Stop-Process Powershell commandlet to loop during stop action
foreach ($bes in $stopbesservice)
$besservice = get-service $bes
if ($besservice.status -eq “Running”) {
Stop-Service $besservice -verbose
Start-Sleep -Seconds 15
if ($besservice.status -eq “Stopping”)
$kill=(Get-WmiObject win32_process -Filter “name = ‘$besservice.exe’”).Terminate()
if ($kill.ReturnValue -eq 0) {Write-Warning “$besservice stopped BY KILLING”}
Start-Sleep -Seconds 1
Write “$besservice stopped”
} else {
Write-Output “service $($besservice) status is $($besservice.status)”


Generally, if the BigFix services do not stop immediately, it is because they are working on finishing up work from a queue or some other requested activity. I’d suggest that it is better to wait for a longer interval (perhaps 60 seconds) before killing the associated process.

Also, there isn’t necessarily a required order to starting or stopping the BigFix Server services.

If the order by which the services are stopped is determined by the $stopbesservice variable then you might want to check that order. I believe it should be BESWebReportsServer, BESClient, GatherDB, FillDB and definitely last BESRootServer. Killing the FillDB process with data in the pipe can never be a good thing I guess but it is hard to be sure. We have never had issues stopping services in the order stated here so we never had to kill either.

Starting and stopping the Bigfix Server

Thank You for feedback. I will adjust the order. Usually we have issues with BESWebReportsServer hangs in Stopping status. I thought that I can capture some kind of error from IEM logs which occurs when IEM related service hangs in stopping status but I was not able to find any information about such logging process.

The WebReports server is generally the slowest service to shut down.

The issue with BES service hangs in Stopping occurs last time in our environment. When I try to stop service via Service GUI Windows error 1053 occurs. I am not sure if the same issue is logged in the EventLog when service is stopped by PowerShell. If yes I will try to look for the error 1053 in the log, and then kill service.