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


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



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: 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, 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