-
-
Save JPMinty/f4d60adafdfbc12b0e4226a27bf1dcb0 to your computer and use it in GitHub Desktop.
Revisions
-
JPMinty revised this gist
Mar 17, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -59,6 +59,8 @@ function Get-ProcessTree } <# Usage: import-module .\Get-ProcessTree.ps1 Get-ProcessTree -Verbose | select Id, Level, IndentedName, ParentId OR for more verbose output: -
JPMinty revised this gist
Mar 17, 2020 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Modified to include support for CommandLine, File Hashes, File Paths, Signing Certificates # Copyright (c) 2020 Jai Minton. All rights reserved. # Copyright (c) 2014 Atif Aziz. All rights reserved. # @@ -36,13 +36,17 @@ function Get-ProcessTree { $id = $process.ProcessId $processCommandLine = $process.CommandLine $parentProcessId = $process.ParentProcessId $process = Get-Process -Id $id -ComputerName $computerName $hash = ($process | gi -ea SilentlyContinue|filehash -ea 0).hash $signingstatus = ($process | gi -ea SilentlyContinue|authenticodesignature -ea 0).status $indent = New-Object String(' ', ($level * $indentSize)) $process ` | Add-Member NoteProperty CommandLine $processCommandLine -PassThru ` | Add-Member NoteProperty ParentId $parentProcessId -PassThru ` | Add-Member NoteProperty Level $level -PassThru ` | Add-Member NoteProperty Hash $hash -PassThru ` | Add-Member NoteProperty signature $signingstatus -PassThru ` | Add-Member NoteProperty IndentedName "$indent$($process.Name)" -PassThru $processByParent.Item($id) ` | ? { $_ } ` @@ -57,7 +61,9 @@ function Get-ProcessTree <# Usage: Get-ProcessTree -Verbose | select Id, Level, IndentedName, ParentId OR for more verbose output: Get-ProcessTree -Verbose | FT Id, Level, IndentedName,ParentId,Path,Hash,CommandLine -AutoSize Get-ProcessTree -Verbose | FT Id, Level, IndentedName,ParentId,Hash,CommandLine -AutoSize Get-ProcessTree -Verbose | FT Id, Level, IndentedName,ParentId,Hash,signature,CommandLine -AutoSize #> -
JPMinty revised this gist
Mar 14, 2020 . 1 changed file with 12 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Modified to include support for CommandLine # Copyright (c) 2020 Jai Minton. All rights reserved. # Copyright (c) 2014 Atif Aziz. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,6 +16,7 @@ # Adapted from http://p0w3rsh3ll.wordpress.com/2012/10/12/show-processtree/ function Get-ProcessTree { [CmdletBinding()] @@ -32,11 +35,13 @@ function Get-ProcessTree function Write-ProcessTree($process, [int]$level = 0) { $id = $process.ProcessId $processCommandLine = $process.CommandLine $parentProcessId = $process.ParentProcessId $process = Get-Process -Id $id -ComputerName $computerName $indent = New-Object String(' ', ($level * $indentSize)) $process ` | Add-Member NoteProperty CommandLine $processCommandLine -PassThru ` | Add-Member NoteProperty ParentId $parentProcessId -PassThru ` | Add-Member NoteProperty Level $level -PassThru ` | Add-Member NoteProperty IndentedName "$indent$($process.Name)" -PassThru $processByParent.Item($id) ` @@ -51,4 +56,8 @@ function Get-ProcessTree <# Usage: Get-ProcessTree -Verbose | select Id, Level, IndentedName, ParentId OR Get-ProcessTree -Verbose | FT Id, Level, IndentedName, ParentId,Path,CommandLine #> -
atifaziz revised this gist
Mar 7, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,8 +17,7 @@ function Get-ProcessTree { [CmdletBinding()] param([string]$ComputerName, [int]$IndentSize = 2) $indentSize = [Math]::Max(1, [Math]::Min(12, $indentSize)) $computerName = ($computerName, ".")[[String]::IsNullOrEmpty($computerName)] -
atifaziz revised this gist
Mar 7, 2014 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,8 @@ function Get-ProcessTree $liveParents = $parents | ? { $pids -contains $_ } $deadParents = Compare-Object -ReferenceObject $parents -DifferenceObject $liveParents ` | select -ExpandProperty InputObject $processByParent = $processes | Group-Object -AsHashTable ParentProcessId function Write-ProcessTree($process, [int]$level = 0) { $id = $process.ProcessId @@ -39,8 +40,8 @@ function Get-ProcessTree | Add-Member NoteProperty ParentId $parentProcessId -PassThru ` | Add-Member NoteProperty Level $level -PassThru ` | Add-Member NoteProperty IndentedName "$indent$($process.Name)" -PassThru $processByParent.Item($id) ` | ? { $_ } ` | % { Write-ProcessTree $_ ($level + 1) } } @@ -50,5 +51,5 @@ function Get-ProcessTree } <# Usage: Get-ProcessTree -Verbose | select Id, Level, IndentedName, ParentId #> -
atifaziz revised this gist
Mar 7, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -35,11 +35,10 @@ function Get-ProcessTree $parentProcessId = $process.ParentProcessId $process = Get-Process -Id $id -ComputerName $computerName $indent = New-Object String(' ', ($level * $indentSize)) $process ` | Add-Member NoteProperty ParentId $parentProcessId -PassThru ` | Add-Member NoteProperty Level $level -PassThru ` | Add-Member NoteProperty IndentedName "$indent$($process.Name)" -PassThru $processes ` | ? { $_.ParentProcessId -eq $id } ` | % { Write-ProcessTree $_ ($level + 1) } -
atifaziz revised this gist
Mar 6, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ function Get-ProcessTree param([string]$ComputerName, [int]$IndentSize = 2) $indentSize = [Math]::Max(1, [Math]::Min(12, $indentSize)) $computerName = ($computerName, ".")[[String]::IsNullOrEmpty($computerName)] $processes = Get-WmiObject Win32_Process -ComputerName $computerName $pids = $processes | select -ExpandProperty ProcessId -
atifaziz revised this gist
Mar 6, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,6 +20,7 @@ function Get-ProcessTree param([string]$ComputerName, [int]$IndentSize = 2) $indentSize = [Math]::Max(1, [Math]::Min(12, $indentSize)) $computerName = ($computerName, ".")[[String]::IsNullOrEmpty($computerName)] $processes = Get-WmiObject Win32_Process -ComputerName $computerName $pids = $processes | select -ExpandProperty ProcessId -
atifaziz revised this gist
Mar 6, 2014 . 1 changed file with 8 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,11 +21,12 @@ function Get-ProcessTree [int]$IndentSize = 2) $computerName = ($computerName, ".")[[String]::IsNullOrEmpty($computerName)] $processes = Get-WmiObject Win32_Process -ComputerName $computerName $pids = $processes | select -ExpandProperty ProcessId $parents = $processes | select -ExpandProperty ParentProcessId -Unique $liveParents = $parents | ? { $pids -contains $_ } $deadParents = Compare-Object -ReferenceObject $parents -DifferenceObject $liveParents ` | select -ExpandProperty InputObject function Write-ProcessTree($process, [int]$level = 0) { @@ -37,7 +38,7 @@ function Get-ProcessTree $process ` | Add-Member NoteProperty ParentId $parentProcessId -PassThru ` | Add-Member NoteProperty Level $level -PassThru ` | Add-Member NoteProperty IndentedName $label -PassThru $processes ` | ? { $_.ParentProcessId -eq $id } ` | % { Write-ProcessTree $_ ($level + 1) } @@ -49,5 +50,5 @@ function Get-ProcessTree } <# Usage: Get-ProcessTree | select Id, Level, IndentedName, ParentId #> -
atifaziz created this gist
Mar 6, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ # Copyright (c) 2014 Atif Aziz. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Adapted from http://p0w3rsh3ll.wordpress.com/2012/10/12/show-processtree/ function Get-ProcessTree { [CmdletBinding()] param([string]$ComputerName, [int]$IndentSize = 2) $computerName = ($computerName, ".")[[String]::IsNullOrEmpty($computerName)] $processes = Get-WmiObject Win32_Process -ComputerName $computerName $pids = $processes | select -ExpandProperty ProcessId $parents = $processes | select -ExpandProperty ParentProcessId -Unique $liveParents = $parents | ? { $pids -contains $_ } $deadParents = Compare-Object -ReferenceObject $parents -DifferenceObject $liveParents | select -ExpandProperty InputObject function Write-ProcessTree($process, [int]$level = 0) { $id = $process.ProcessId $parentProcessId = $process.ParentProcessId $process = Get-Process -Id $id -ComputerName $computerName $indent = New-Object String(' ', ($level * $indentSize)) $label = "$indent$($process.Name)" $process ` | Add-Member NoteProperty ParentId $parentProcessId -PassThru ` | Add-Member NoteProperty Level $level -PassThru ` | Add-Member NoteProperty IdentedName $label -PassThru $processes ` | ? { $_.ParentProcessId -eq $id } ` | % { Write-ProcessTree $_ ($level + 1) } } $processes ` | ? { $_.ProcessId -ne 0 -and ($_.ProcessId -eq $_.ParentProcessId -or $deadParents -contains $_.ParentProcessId) } ` | % { Write-ProcessTree $_ } } <# Usage: Get-ProcessTree | select Id, Level, IdentedName, ParentId #>