Skip to content

Instantly share code, notes, and snippets.

@junecastillote
Last active September 29, 2023 16:06
Show Gist options
  • Save junecastillote/80aa26aedc21cbe0dbe545ca17348de0 to your computer and use it in GitHub Desktop.
Save junecastillote/80aa26aedc21cbe0dbe545ca17348de0 to your computer and use it in GitHub Desktop.
Get the status of a service's required services
# 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