@@ -4937,19 +4937,17 @@ function Get-RunningService {
49374937 [NtApiDotNet.Win32.ServiceState ]$State = " Active" ,
49384938 [parameter (Mandatory , ParameterSetName = " FromArgs" )]
49394939 [NtApiDotNet.Win32.ServiceType ]$ServiceType = 0 ,
4940- [parameter (ParameterSetName = " FromName" , Position = 0 )]
4940+ [parameter (Mandatory , ParameterSetName = " FromName" , Position = 0 )]
49414941 [string []]$Name
49424942 )
49434943
49444944 PROCESS {
49454945 switch ($PSCmdlet.ParameterSetName ) {
49464946 " All" {
4947+ $ServiceType = [NtApiDotNet.Win32.ServiceUtils ]::GetServiceTypes()
49474948 if ($Driver ) {
49484949 $ServiceType = [NtApiDotNet.Win32.ServiceUtils ]::GetDriverTypes()
49494950 }
4950- else {
4951- $ServiceType = [NtApiDotNet.Win32.ServiceUtils ]::GetServiceTypes()
4952- }
49534951
49544952 if ($IncludeNonActive ) {
49554953 $State = " All"
@@ -4958,10 +4956,10 @@ function Get-RunningService {
49584956 $State = " Active"
49594957 }
49604958
4961- Get-Win32Service - State $State - ServiceType $ServiceType
4959+ Get-Win32Service - State $State - Type $ServiceType
49624960 }
49634961 " FromArgs" {
4964- Get-Win32Service - State $State - ServiceType $ServiceType
4962+ Get-Win32Service - State $State - Type $ServiceType
49654963 }
49664964 " FromName" {
49674965 Get-Win32Service - Name $Name
@@ -4994,6 +4992,12 @@ Get all active services.
49944992. EXAMPLE
49954993Get-Win32Service -State All -Type UserService
49964994Get all user services.
4995+ . EXAMPLE
4996+ Get-Win32Service -ProcessId 1234
4997+ Get services running in PID 1234.
4998+ . EXAMPLE
4999+ Get-Win32Service -Name WebClient
5000+ Get the WebClient service.
49975001#>
49985002function Get-Win32Service {
49995003 [CmdletBinding (DefaultParameterSetName = " All" )]
@@ -5002,8 +5006,10 @@ function Get-Win32Service {
50025006 [NtApiDotNet.Win32.ServiceState ]$State = " All" ,
50035007 [parameter (ParameterSetName = " All" )]
50045008 [NtApiDotNet.Win32.ServiceType ]$Type = 0 ,
5005- [parameter (ParameterSetName = " FromName" , Position = 0 )]
5006- [string []]$Name
5009+ [parameter (Mandatory , ParameterSetName = " FromName" , Position = 0 )]
5010+ [string []]$Name ,
5011+ [parameter (Mandatory , ParameterSetName = " FromPid" , Position = 0 )]
5012+ [int []]$ProcessId
50075013 )
50085014
50095015 PROCESS {
@@ -5019,6 +5025,9 @@ function Get-Win32Service {
50195025 [NtApiDotNet.Win32.ServiceUtils ]::GetService($n ) | Write-Output
50205026 }
50215027 }
5028+ " FromPid" {
5029+ Get-Win32Service - State Active | Where-Object {$_.ProcessId -in $ProcessId }
5030+ }
50225031 }
50235032 }
50245033}
0 commit comments