mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Added Service User to Service provider for each service
This commit is contained in:
parent
bbaca8d45b
commit
95cfaf4638
1 changed files with 32 additions and 12 deletions
|
|
@ -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
|
#Dependent / Child
|
||||||
foreach ($dependency in $service.ServicesDependedOn) {
|
foreach ($dependency in $service.DependentServices) {
|
||||||
if ($null -eq $DependingServices) { $DependingServices = @(); }
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue