script to check a folder and get all file size in subfolder

Posted on 2011-09-13
Last Modified: 2012-05-12

I need a script to get all file size (MB) in a specific folder and all subfolder.

the script must export to a csv file the result with all information like this:


Question by:cawasaki
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Expert Comment

by:Ryan Weaver
ID: 36528561
How about something like Get-DiskUsage by Joel Bennett
LVL 54

Expert Comment

by:Bill Prew
ID: 36528932
Do you want just one total for the specified folder, or a line for each subfolder as well?

LVL 54

Accepted Solution

Bill Prew earned 500 total points
ID: 36529069
Here's a starting place for you, save as a VBS and adjust the directory name at the top. It displays the results to the screen, but you can easily place into a file using redirection, as in:

cscript //nologo filesze.vbs > filesize.csv

sFolder = "c:\ee\temp"

Set oFS = WScript.CreateObject("Scripting.FileSystemObject")

ShowFolderDetails oFS.GetFolder(sFolder)

Sub ShowFolderDetails(oFolder)
   For Each oFile in oFolder.Files
      Wscript.echo oFolder.Path & "," & oFile.Name & "," & Round(oFile.Size / 1024 / 1024, 2)
   For Each oSubFolder In oFolder.Subfolders
End Sub

Open in new window

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.


Author Comment

ID: 36529147
i need one line by file :)

Author Comment

ID: 36529158
hi Fryguy,

your link of powershell function is cool, can you explain me how i can use it? how i can add this function?

LVL 54

Expert Comment

by:Bill Prew
ID: 36529167
==> i need one line by file :)

Okay, that's what the VB script above does.


Author Closing Comment

ID: 36534993
thanks good its work perfectly

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Matching variables and Compare-Object 24 52
Powershell script include embedded images 10 42
Help to debug powershell script 5 38
Export AD group members. 1 22
A brief introduction to what I consider to be the best editor for PowerShell.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question