The 2011 Scripting Games Beginner Event 8: Use PowerShell to Report Disk Space Utilization

The 2011 Scripting Games Beginner Event 8: Use PowerShell to Report Disk Space Utilization

  • Comments 8
  • Likes

2011 Scripting Games badge

Summary: Beginner Event 8 of 2011 Scripting Games uses Windows PowerShell to report disk space that is consumed by files in a folder.

About this event

Division

Beginner

Date of Event

4/13/2011 12:01 AM

Due Date

4/20/2011 12:01 AM

Event scenario

You are concerned with the shrinking amount of free disk space on your computer. After some preliminary work, you have narrowed down the problem to one particular folder. You decide to obtain a listing of all the files in the folder, and write the information from the directory listing to a comma-separated value (CSV) file so that you can open the CSV file in a Microsoft Excel spreadsheet for further analysis. A sample output is shown in the following image.

Design points

  • You have determined that you need the file name, file size, and the date that the file was last modified to aid you in your analysis.
  • To make the process go smoother, you should have your script automatically open the CSV file in Microsoft Excel.
  • Use any folder on your computer that you wish—the number of files or size of the files is not a concern for this exercise.
  • Extra points for a script that allows you to specify alternate folders at run time (that is, the script uses parameters and therefore does not require you to edit the script prior to running).
  • Extra points for writing a function that is designed as reusable code.

2011 Scripting Games links

2011 Scripting Games: All Links on One Page

Submit your scripts on PoshCode

Support our Sponsors!

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. Good luck as you compete in this year’s Scripting Games. We wish you well.

Ed Wilson, Microsoft Scripting Guy

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Thankyou for this challenge, I have submitted mine about an hour ago. I decided to go against the formatting Name Length WriteTime I hope this does not deduct points?

  • @adam

    not a problem. in fact i loved your script.

  • Is having the data automatically separated into their own columns in Excel a requirement for this challenge?

  • @Chee Vang as opposed to having all of the data showing up in a single column, yes. If you have a better way of displaying the data that will make a better script, I would like to see it. Remember, the output is simply a sample output that might meet the requirement. If you want to do something better, I am looking forward to it.

  • Must the script only process the "current" folder or also recursively process the content of existing files in subfolders?

  • @André

    You only need to process the current folder. You may wish to allow it to recurse, but that would be for extra points (as would be allowing it to specify alternate folders)

  • Hi Ed, I hope all is well and Love the games I am learning a sleuth of knowledge.

    2 of my scripts one for event 8 beginner and for advanced event # 9 have not been scored. Is this okay?

    I know they are on the posh code site since yesterday but with no one looking at them. Let me know and thanks for everything.

    http://www.techjunkie.tv

  • @scott

    Yes it is quite normal for your scripts to have not been graded yet. Many of the judges, including myself, have been in Vegas for the last several days attending the powershell deep dive. I am at airport right now on way home - using my windows 7 mobile phone to answer you. I will begin grading scripts again tomorrow and will continue throughout the weekend until the final leader board on Monday.