Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-WmiObject - Invalid class "Win32_Service" - Workaround #33322

Merged
merged 12 commits into from
Nov 3, 2022
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix concurrent map writes when system/process code called from reporter code {pull}32491[32491]
- Fix in AWS related services initialisation relying on custom endpoint resolver. {issue}32888[32888] {pull}32921[32921]
- Keep `orchestrator.cluster.name` if `kubeconfig` is not returned in GKE metadata. {pull}33418[33418]
- Fix Windows service install/uninstall when Win32_Service returns error, add logic to wait until the Windows Service is stopped before proceeding. {pull}33322[33322]
- Support for multiline zookeeper logs {issue}2496[2496]

*Auditbeat*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Delete and stop the service if it already exists.
if (Get-Service {{.BeatName}} -ErrorAction SilentlyContinue) {
$service = Get-WmiObject -Class Win32_Service -Filter "name='{{.BeatName}}'"
$service.StopService()
Stop-Service {{.BeatName}}
(Get-Service {{.BeatName}}).WaitForStatus('Stopped')
Start-Sleep -s 1
$service.delete()
sc.exe delete {{.BeatName}}
}

$workdir = Split-Path $MyInvocation.MyCommand.Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Delete and stop the service if it already exists.
if (Get-Service {{.BeatName}} -ErrorAction SilentlyContinue) {
$service = Get-WmiObject -Class Win32_Service -Filter "name='{{.BeatName}}'"
$service.StopService()
Stop-Service {{.BeatName}}
(Get-Service {{.BeatName}}).WaitForStatus('Stopped')
Start-Sleep -s 1
$service.delete()
sc.exe delete {{.BeatName}}
}