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.
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:
- How many stopped services are on your computer?
- list services set to autostart but are NOT running?
- List ONLY the property names of the Win32_BIOS WMI class.
- List all loaded functions displaying the name, number of parameter sets, and total number of lines in the function.
- Create a formatted report of Processes grouped by UserName. Skip processes with no user name.
- Using your previous code, display the username, the number of processes, the total workingset size. Set no username to NONE.
- Create a report that shows files in %TEMP% by extension. Include Count,total size, % of total directory size.
- 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:
- Create a directory called C:\DataFiles
- 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. - 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
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
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
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
Hi Jeff,
Have enough weeks passed now? Could you post your solutions as promised, please?
Thanks for sharing.
Looks like I dropped the ball on this one. You can find solutions at https://gist.github.com/jdhitsolutions/e82e86efad8ed1ca1f66612d87c6e409