# Delete and stop the service if it already exists.
if (Get-Service metricbeat -ErrorAction SilentlyContinue) {
  Stop-Service metricbeat
  (Get-Service metricbeat).WaitForStatus('Stopped')
  Start-Sleep -s 1
  sc.exe delete metricbeat
}
