A PowerShell Object Age Challenge

One of PowerShell’s greatest strengths is its ease of use and flexibility. There are many things you do in PowerShell that could be a whole lot more complicated. For example, you don’t have to learn different commands for navigating the registry than what you use for the file system. The same command, Get-ChildItem, can work in both. True, you have to learn a few things depending on where you are running the command. This is also true for commands like Select-Object and Measure-Object. They are generic and flexible enough to use with any type of object.


For your next challenge the Chairman would like you to create an advanced function called Get-ObjectAge. Many things that you manage with PowerShell have an age. Think of files, processes, Active Directory objects, and more. These objects often have properties that indicate when the object was created and when it was last modified or updated. Obviously, the property names vary.

Your task is to create a generic function that can be used with any group of objects as input. The output should show the object’s creation time, when it was last modified, and its age from creation. You also need to define a property that indicates if the creation age is above or below, the average of all processed objects. Finally, it would be nice to allow the user to specify additional object properties to display.

You can assume the user of your function will be able to specify the property names to use. Although, if you want to build some mechanism to autodetect the correct properties, The Chairman won’t stand in your way.


Given the generic nature of the command, formatted output might be tricky. But not impossible if you limit your focus. See if you can create the function and other necessary files to give you nicely formatted results for common file types like process, file, and Active Directory User account. If you tackle this bonus, format timespans without the millisecond component.

You might also consider using ANSI formatting to display Above average objects in a different color.

5 Replies to “A PowerShell Object Age Challenge”

  1. Wolfgang (danubie)

    This is my second participation to an Iron Scripter Challenge.

    Once again it’s been interesting to work on an ‘abstract’ problem you wouldn’t have thought upon. And again I had a lot of learnings while creating my solution.
    – Where to place a local function to not expose it to the wild (usually I work on modules where you just don’t export them) when working with pipeline
    – generic functions are harder to design
    – abstract problems can bring new ideas to you to be used in your every days life

    Sorry, that I missed the bonus, but a awaiting new learnings from others solutions.

    If you want to have a look in my repo:

    Thanks for your effort in creating puzzles.

Comments are closed.