Building a PowerShell Process Tree

Your next PowerShell scripting challenge has arrived. Some of you may be familiar with the tree command-line tool. If you’ve never seen it, try tree $home at a PowerShell prompt. On non-Windows machines you may need to install an additional package. The point of the command is to graphically display hierarchical content from a command prompt.

Since processes can have child processes there is an implied hierarchy. The Chairman would like you to write a PowerShell equivalent of the tree command but for processes.

Intermediate Requirements

  • The topmost level should be the computer name.
  • At a minimum, you should display a tree version using the process name.
  • Use ASCII characters to display the “tree” branches.

Advanced Requirements

Once you’ve met the above requirements see how many of these items you can accomplish.

  • Query remote computers.
  • Use ANSI or extended characters for the tree.
  • Include the ProcessID or other user-specified properties.
  • Take into account orphaned processes – those whose parent is no longer running.
  • Colorize output on criteria of your choice such as run time, company name, user ID, or Working Set size.

Bonus Elements

Adding any of these features will truly set your code apart.

  • Allow some type of filtering for the associated user name.
  • Allow some type of sorting such as by name or start time,
  • Export the graphical tree to an HTML file,
  • Work cross-platform.

As always, please post links to your work and solutions. Good luck!

3 Replies to “Building a PowerShell Process Tree”

Leave a Reply

Your email address will not be published. Required fields are marked *