Added Service User to Service provider for each service

This commit is contained in:
Lord Hepipud 2019-09-25 19:58:37 +02:00
parent bbaca8d45b
commit 95cfaf4638

View file

@ -5,6 +5,13 @@ function Get-IcingaServices()
) )
$ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue; $ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue;
$ServiceWmiInfo = $null;
if ($Service.Count -eq 0) {
$ServiceWmiInfo = Get-WmiObject Win32_Service;
} else {
$ServiceWmiInfo = Get-WmiObject -Class Win32_Service | Where-Object { $Service -Contains $_.Name } | Select-Object StartName, Name;
}
if ($null -eq $ServiceInformation) { if ($null -eq $ServiceInformation) {
return $null; return $null;
@ -14,20 +21,32 @@ function Get-IcingaServices()
foreach ($service in $ServiceInformation) { foreach ($service in $ServiceInformation) {
[array]$DependentServices = $null; [array]$DependentServices = $null;
[array]$DependingServices = $null; [array]$DependingServices = $null;
[string]$ServiceUser = '';
#Dependent / Child foreach ($wmiService in $ServiceWmiInfo) {
foreach ($dependency in $service.DependentServices) { if ($wmiService.Name -eq $service.ServiceName) {
if ($null -eq $DependentServices) { $DependentServices = @(); } $ServiceUser = $wmiService.StartName;
$DependentServices += $dependency.Name; break;
} }
}
#Depends / Parent
foreach ($dependency in $service.ServicesDependedOn) { #Dependent / Child
if ($null -eq $DependingServices) { $DependingServices = @(); } foreach ($dependency in $service.DependentServices) {
if ($null -eq $DependentServices) {
$DependentServices = @();
}
$DependentServices += $dependency.Name;
}
#Depends / Parent
foreach ($dependency in $service.ServicesDependedOn) {
if ($null -eq $DependingServices) {
$DependingServices = @();
}
$DependingServices += $dependency.Name; $DependingServices += $dependency.Name;
} }
$ServiceData.Add( $ServiceData.Add(
$service.Name, @{ $service.Name, @{
@ -57,6 +76,7 @@ function Get-IcingaServices()
'raw' = [int]$service.StartType; 'raw' = [int]$service.StartType;
'value' = $service.StartType; 'value' = $service.StartType;
}; };
'ServiceUser' = $ServiceUser;
} }
} }
); );