Skip to content

Instantly share code, notes, and snippets.

@Nillth
Created November 23, 2021 05:52
Show Gist options
  • Save Nillth/1afe56ae81d8ea2279cc194969ca24c7 to your computer and use it in GitHub Desktop.
Save Nillth/1afe56ae81d8ea2279cc194969ca24c7 to your computer and use it in GitHub Desktop.
Get Service Path
Function Get-ServicePath($Name)
{
#Find the repository service
$WinService = Get-WmiObject win32_service | ?{ $_.Name -eq $Name } | select Name, DisplayName, State, PathName
[regex]$EXEPath = '(\\\\|\w:)(.+)(\..{3})'
if ($WinService.PathName -match $EXEPath) { [System.IO.FileInfo]$WinServicePath = $Matches[0] }
$WinService | Add-Member -MemberType NoteProperty -Name Path -Value $WinServicePath
$WinService
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment