Last active
September 29, 2023 16:06
-
-
Save junecastillote/80aa26aedc21cbe0dbe545ca17348de0 to your computer and use it in GitHub Desktop.
Get the status of a service's required services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get-ServiceDependecyStatus.ps1 | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[System.Object[]] | |
$ServiceList | |
) | |
foreach ($currentService in $ServiceList) { | |
try { | |
if (($currentService | Get-Member).TypeName -eq 'System.String') { | |
$service = Get-Service $currentService -ErrorAction Stop | |
} | |
if (($currentService | Get-Member).TypeName -like "*ServiceController*") { | |
$service = $currentService | |
} | |
} | |
catch { | |
continue | |
} | |
# Return the result | |
[PSCustomObject]@{ | |
Name = $service.Name | |
Status = $service.Status | |
StartType = $service.StartType | |
RequiredServicesNotRunning = @(($service.RequiredServices | Where-Object { $_.Status -ne 'Running' }).Name) -join ";" | |
RequiredServicesRunning = @(($service.RequiredServices | Where-Object { $_.Status -eq 'Running' }).Name) -join ";" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment