mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Return service name, display name, start mode and state from win_service module.
This commit is contained in:
parent
67e56853d3
commit
efc07cf627
1 changed files with 17 additions and 2 deletions
|
@ -48,14 +48,27 @@ $svc = Get-Service -Name $svcName -ErrorAction SilentlyContinue
|
||||||
If (-not $svc) {
|
If (-not $svc) {
|
||||||
Fail-Json $result "Service '$svcName' not installed"
|
Fail-Json $result "Service '$svcName' not installed"
|
||||||
}
|
}
|
||||||
|
# Use service name instead of display name for remaining actions.
|
||||||
|
If ($svcName -ne $svc.ServiceName) {
|
||||||
|
$svcName = $svc.ServiceName
|
||||||
|
}
|
||||||
|
|
||||||
|
Set-Attr $result "name" $svc.ServiceName
|
||||||
|
Set-Attr $result "display_name" $svc.DisplayName
|
||||||
|
|
||||||
If ($startMode) {
|
|
||||||
$svcMode = Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='$svcName'"
|
$svcMode = Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='$svcName'"
|
||||||
|
If ($startMode) {
|
||||||
If ($svcMode.StartMode.ToLower() -ne $startMode) {
|
If ($svcMode.StartMode.ToLower() -ne $startMode) {
|
||||||
Set-Service -Name $svcName -StartupType $startMode
|
Set-Service -Name $svcName -StartupType $startMode
|
||||||
Set-Attr $result "changed" $true
|
Set-Attr $result "changed" $true
|
||||||
|
Set-Attr $result "start_mode" $startMode
|
||||||
}
|
}
|
||||||
|
Else {
|
||||||
|
Set-Attr $result "start_mode" $svcMode.StartMode.ToLower()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
Set-Attr $result "start_mode" $svcMode.StartMode.ToLower()
|
||||||
}
|
}
|
||||||
|
|
||||||
If ($state) {
|
If ($state) {
|
||||||
|
@ -87,5 +100,7 @@ If ($state) {
|
||||||
Set-Attr $result "changed" $true;
|
Set-Attr $result "changed" $true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$svc.Refresh()
|
||||||
|
Set-Attr $result "state" $svc.Status.ToString().ToLower()
|
||||||
|
|
||||||
Exit-Json $result;
|
Exit-Json $result;
|
||||||
|
|
Loading…
Reference in a new issue