solovur.blogg.se

Sorting folders by size
Sorting folders by size









I then pick up the path itself from the folder object returned by the GetFolder method. I use the FullName property obtained by the Get-ChildItem cmdlet and turn it into a string by calling the ToString method. The GetFolder method from the FileSystemObject requires a string that is the path to the folder. The first property is the path to the folder (I call it name) and the second property is the size of the folder in megabytes (stored in a property called size). I create a custom psobject that contains two properties. This command is shown here.įoreach($folder in (Get-ChildItem $path -Directory -Recurse)) I am interested in the folders as well as the subfolders, so I use the –recurse parameter. I do this by using the Windows PowerShell 3.0 syntax to return directories only. The next thing I need to do is to get a listing of the paths to the folders I am interested in exploring. $fso = New-Object -ComObject scripting.filesystemobject With this in mind, I need to use the New-Object cmdlet with the –comobject parameter to create an instance of the filesystemobject, as shown here.

sorting folders by size

The old-fashioned COM object, Scripting.FileSystemObject returns a folder size. The thing is that I had forgotten about it until I saw Jeff’s script on his blog. I mean, I wrote two books on VBScript (three if you count my WMI book as well), so I am certain that I knew this. I know that I knew this … but hey, I forget stuff after a while. Use the FileSystem object to find folder sizes (OK, so I have now given credit to Jeff and to Don … so now on with the blog post). It may be partially because, hey, it is the weekend, and on the weekends, I like to play around with Windows PowerShell (my buddy Don Jones used to write a column called PowerShell with a purpose-well, when I am playing around on the weekend, I could call it PowerShell without a purpose … but then I would never purposefully infringe on anyone’s title.

sorting folders by size sorting folders by size

I recently ran across a function written by Jeff Wouters that caused me to decide to write this script yet again. It is amazing how things continue to go in circles … I know I have written a script to sort folders by size many times in many different languages. Microsoft Scripting Guy, Ed Wilson, is here. Summary: Microsoft Scripting Guy, Ed Wilson, uses Windows PowerShell 3.0 to sort folders by size.











Sorting folders by size