Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell Puzzles and Challenges

Posted on February 3, 2021July 30, 2021

I just wrapped up presenting to the Research Triangle PowerShell User Group. I gave them a set of PowerShell problems to solve. The idea is that in solving the problem, you improve your PowerShell skills and expertise. Tonight's problems were not scripting problems. The answers to these puzzles are not limited to one-line commands, although some might. Most of these problems should be solved with no more than a few lines of PowerShell code that you would run interactively at a PowerShell prompt.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

We didn't get through all of the problems, so I am going to post them here. If you did not attend the meeting, you are still welcome to try your hand at solving them. The first few problems are not especially complex, but everyone starts as a beginner so I wanted to include those people as well.

See what you can do with these:

  1. How many stopped services are on your computer?
  2. list services set to autostart but are NOT running?
  3. List ONLY the property names of the Win32_BIOS WMI class.
  4. List all loaded functions displaying the name, number of parameter sets, and total number of lines in the function.
  5. Create a formatted report of Processes grouped by UserName. Skip processes with no user name.
  6. Using your previous code, display the username, the number of processes, the total workingset size. Set no username to NONE.
  7. Create a report that shows files in %TEMP% by extension. Include Count,total size, % of total directory size.
  8. Find the total % of WS memory a process is using. Show top 10 processes,count,total workingset and PctUsedMemory.

There is almost certainly more than one way to accomplish these tasks. You can use either Windows PowerShell or PowerShell 7.x. I wrote all of my solutions to work in Windows PowerShell.

Bonus

I also have 2 bonus challenges. These are a bit more involved and will likely be easier with a PowerShell script or function.

Bonus #1

Write PowerShell code to achieve the following goals:

  1. Create a directory called C:\DataFiles
  2. Create 25 files of varying sizes between 1KB and 1MB with your own naming convention.
    But don't use something as simple as Test-1. Files should have a .dat extension.
  3. Modify the creation and last write times to "age" the files between 10 and 100 days.

You might find it easier to create a simple PowerShell script file. Don't worry about error handling, parameters, or any scripting-related concepts.

Bonus #2

Create a formatted HTML report that shows each module location from %PSModulePath%, the number of modules in each location and their total size, and then a listing of each module which shows the most recent version and the total size of all module files.

Extra bonus points if you can make it pretty with CSS formatting.

Where Are the Answers?

You are welcome to leave a comment with links to your work. And if you are looking for even more challenges, check out https://ironscripter.us. Enjoy and Learn!

July 30, 2021: You can find all of my solutions at https://gist.github.com/jdhitsolutions/e82e86efad8ed1ca1f66612d87c6e409


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

5 thoughts on “PowerShell Puzzles and Challenges”

  1. Doug Finke says:
    February 4, 2021 at 4:33 pm

    Here’s a solution to the first challenge.
    How many stopped services are on your computer?

    It exports to Excel, and includes Pivot Tables, filtering, and colorizing based on the data in the Excel cells.

    https://gist.github.com/dfinke/53a7a16a742255c0c00edd45cb74ee34

  2. Peter Charleston says:
    February 6, 2021 at 2:43 pm

    Hi Jeff,
    Here are my solutions:

    https://pcautomations.com/2021/02/06/powershell-puzzles-and-challenges/

    I got a bit lost on Question 8 so I don’t think my answer is right.

    Peter

  3. Peter Charleston says:
    February 6, 2021 at 2:44 pm

    Hi Jeff,
    Here are my solutions:

    https://pcautomations.com/2021/02/06/powershell-puzzles-and-challenges/

    I got a bit lost on Question 8 so I don’t think my answer is right.

    Peter

  4. Urs Rau says:
    July 30, 2021 at 3:49 am

    Hi Jeff,
    Have enough weeks passed now? Could you post your solutions as promised, please?
    Thanks for sharing.

    1. Jeffery Hicks says:
      July 30, 2021 at 9:27 am

      Looks like I dropped the ball on this one. You can find solutions at https://gist.github.com/jdhitsolutions/e82e86efad8ed1ca1f66612d87c6e409

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d