Being away from my blogging a while, for the scripting of the migration of 400 ftp users to new server, Today, I finalized a script that will list folders/file sizes recursively that I started writing a few days ago. We can also use TreeSize Free to graphically list folder sizes. Here in powershell, I’m going to show you the use of recursive functions to list folders sizes as being added from child directories sizes. Combined with Powershell remoting, you can use this script to remotely query users’ profile sizes on remote computers.Two good points about this script are:
1) You can list the folder sizes recursively.
2) You can limit the depth of listing files/folders.
What this script will do:
You can choose one of these options at a time, depending on parameters.
1) It will list folder sizes recursively or to a specified level.
2) It will list folder sizes, counting only the specific file type recursively or to a specified level.
3) It will list folder sizes with the above options with guided lines for easy viewing.
4) It will list file sizes at the specified level or up to a specified level.
5) It will list file sizes, counting only the specific file type at the specified level or up to a specified level.
Open the powershell as “Run as Administrator” before you run the script.
Here is a few usage examples.
To list directory sizes under current directory.
.\Get_Folder_Sizes -level 1 -Display
To list directory sizes only with *.exe files type under c:windows directory.
.\Get_Folder_Sizes -Directory c:\Windows -level 1 -FileType exe -Display
To list *.exe file sizes under next child-level directory only. (Level 1 is for files in current directory)
.\Get_Folder_Sizes -Level 2 -FileOnly -FileType exe
To list *.exe files sizes & display up to next 2 level.
.\Get_Folder_Sizes -ToLevel 2 -FileOnly -FileType exe
To Export local users’ profile folders sizes to csv
.\Get_Folder_Sizes -Directory C:\Users -Level 1 | Export-Csv -NoTypeInfo C:\UsersUsers_Profiles_Sizes.csv
You can download my script from github.