ps/Modules/Alkami.PowerShell.Services/Public/Get-WindowsServiceApplicationName.ps1

36 lines
1.2 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
function Get-WindowsServiceApplicationName {
<#
.SYNOPSIS
Gets the full file path to a Windows service's application executable
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$serviceName
)
$logLead = (Get-LogLeadName)
Write-Host "$logLead : Querying WMI for ServiceInformation for $serviceName"
$serviceDetail = Get-CIMInstance win32_service -Filter "Name like '%$serviceName%'"
if ($null -eq $serviceDetail) {
Write-Warning "$logLead : Unable to find service detail for service with name $serviceName"
return $null
} elseif ($null -eq $serviceDetail.PathName) {
# This should never happen. Probably.
Write-Warning "$logLead : Unable to find the property PathName for service with name $serviceName"
return $null
} elseif ($serviceDetail.Count -gt 1) {
# This shouldn't happen either if you're using it right.
Write-Warning "$logLead : More than one service found using service name filter $serviceName. Check the input parameter!"
#return $null
}
return ($serviceDetail | Select-Object -First 1 | Select-Object -ExpandProperty PathName)
}