Created
November 23, 2021 05:52
-
-
Save Nillth/1afe56ae81d8ea2279cc194969ca24c7 to your computer and use it in GitHub Desktop.
Get Service Path
This file contains hidden or 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
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