jhorsman
10/5/2017 - 12:35 PM

Get SDL Web Content Delivery service information from the Windows Registry

Get SDL Web Content Delivery service information from the Windows Registry

# Firgure out wehter to wite output to host and get a nice list of JVM options. Or ouput the object so that output can be chained
# i.e. .\get-service-registry3.ps1 | Format-List

# todo add parameter for service name, which allows wildcard

# The SDL Web Content Delivery services use Procrun, which in turn uses the Windows registry.
# See https://commons.apache.org/proper/commons-daemon/procrun.html
# HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<ServiceName>
# HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\ProcRun 2.0\<ServiceName>\Parameters
# HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\ProcRun 2.0\<ServiceName>

$services = Get-Service | Where {$_.Name.Contains("SDL")}
#$services = Get-Service SDLWebStagingDeployerService


foreach ($service in $services) {
    $serviceName = $service.Name
    $serviceInfo = New-Object psobject
    $properties = Get-ItemProperty "HKLM:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\$serviceName"
    $serviceInfo | Add-Member –MemberType NoteProperty -Name ServiceName -Value $properties.PSChildName
    $serviceInfo | Add-Member –MemberType NoteProperty -Name DisplayName -Value $properties.DisplayName
    $serviceInfo | Add-Member –MemberType NoteProperty -Name DependOnService -Value ($properties.DependOnService -join ', ')

    $properties = Get-ItemProperty -Path "HKLM:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\ProcRun 2.0\$serviceName\Parameters\Java"
    $serviceInfo | Add-Member –MemberType NoteProperty -Name JvmOptions -Value $properties.Options

    # Output a nice table
    #Write-Output $serviceInfo
    
    Write-Host ("Service name: " + $serviceInfo.ServiceName)
    Write-Host ("Display name: " + $serviceInfo.DisplayName)
    Write-Host ("Depend on service: " + $serviceInfo.DependOnService)
    Write-Host "JVM options: "
    $serviceInfo.JvmOptions
    Write-Host " "
}