Function Get-Process { [CmdletBinding(DefaultParameterSetName=‘Name’, HelpUri=‘http://go.microsoft.com/fwlink/?LinkID=113324’' , RemotingCapability=‘SupportedByCommand’)] param( [Parameter(ParameterSetName=‘Name’, Position=0, ValueFromPipelineByPropertyName=$true)] [Alias(‘ProcessName’)] [ValidateNotNullOrEmpty()] [string[]] ${Name}, [Parameter(ParameterSetName=‘Id’, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [Alias(‘PID’)] [int[]] ${Id}, [Parameter(ValueFromPipelineByPropertyName=$true)] [Alias(‘Cn’)] [ValidateNotNullOrEmpty()] [string[]] ${ComputerName}, [ValidateNotNull()] [switch] ${Module}, [Alias(‘FV’,‘FVI’)] [ValidateNotNull()] [switch] ${FileVersionInfo}, [Parameter(ParameterSetName=‘InputObject’, Mandatory=$true, ValueFromPipeline=$true)] [System.Diagnostics.Process[]] ${InputObject}, [ValidateNotNull()] [switch] ${ShowChain}) begin { function Get-ProcessChain { [cmdletbinding()] Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true,ValueFromPipelineByPropertyName = $true)] [System.Diagnostics.Process]$ProcessObject ) Begin { $DefaultFColor = $Host.UI.RawUI.ForegroundColor $ArrayContains = @() } process { if ($ArrayContains -notcontains $ProcessObject.ID ) { $ProcessObject if ($ProcessObject.name -ne ‘services’) { $ComputerName = $ProcessObject.MachineName $Beforecaption = ‘-‘ $ProcessMotherID = $ProcessObject.ID do { $Hasharguments = @{ Filter = “ParentProcessId='$($ProcessMotherID)'” Property = "ProcessID,Name" ErrorAction = "SilentlyContinue" ComputerName = $ComputerName } $ProcessChild = Get-WmiObject win32_process @Hasharguments if ($ProcessChild ) { $Beforecaption += ‘-‘ $Host.UI.RawUI.ForegroundColor = “Yellow” $ProcessChild | ForEach-Object { Get-Process -Id $_.Processid -ComputerName $ComputerName -ErrorAction SilentlyContinue | Add-Member -MemberType NoteProperty -name ProcessName -Value “$Beforecaption $($_.Name)” -Force -PassThru $ProcessMotherID = $_.Processid $ArrayContains+= $_.Processid } } else { $Beforecaption = ‘-‘ Break } } while($true) $Host.UI.RawUI.ForegroundColor = $DefaultFColor } } } } try { $outBuffer = $null if ($PSBoundParameters.TryGetValue(‘OutBuffer’, [ref]$outBuffer)) { $PSBoundParameters[‘OutBuffer’] = 1 } $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(‘Get-Process’, [System.Management.Automation.CommandTypes]::Cmdlet) if ($PSBoundParameters[‘ShowChain’]) { [Void]$PSBoundParameters.Remove(“ShowChain”) $scriptCmd = {& $wrappedCmd @PSBoundParameters | Get-ProcessChain} } else { $scriptCmd = {& $wrappedCmd @PSBoundParameters} } $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) $steppablePipeline.Begin($PSCmdlet) } catch { throw } } process { try { $steppablePipeline.Process($_) } catch { throw } } end { try { $steppablePipeline.End() } catch { throw } } } <# .ForwardHelpTargetName Get-Process .ForwardHelpCategory Cmdlet #>