Getting Sizes of Directories within a folder/drive and exporting to a CSV using PowerShell

Alright so I have

“Get-ChildItem -Directory | Select Name | Export-Csv “test.csv” -Encoding UTF8”

which gets me the directories in a folder so a .csv I would like to also output the size of those folders to the CSV (not the files within or subdirectories).

I know Ill likely have to use Measure-Object and pipe to it from Get-ChildItem but its seems to be unhappy when I use -Directory

Looking for some help here as quite a bit of searching and playing around with thing I Havnt come up with a solution. If possible displaying the size in GB would be preferred but that is a lesser issue at this time.

Thanks in advance.

Also new to here still and am rather used to old school forums so if this need to be moved or relabeled be my guest and let me know what to do next time.

What version of Powershell do you have?

Check out Get-FolderSize if you have PowerShell v3 or higher.

Get-Foldersize | Select "FolderName","Size(GB)","FullPath" | Export-Csv "test.csv" -Encoding UTF8

Looking good so far. Any idea why certain folders dont show an amount? Only thing I can see similar about the folders is that they have “[ ]” in the name.

Did you try running just Get-FolderSize without using the select which shows both MB and GB?

could you clarify on that? If i run:

Get-Foldersize | Select "FolderName","Size","FullPath" | Export-Csv "test.csv" -Encoding UTF8
Get-Foldersize | Select "FolderName","Size()","FullPath" | Export-Csv "test.csv" -Encoding UTF8

Nothing is populated in any of the size fields.

Sorry about that. I meant take out the pipe to select from the command entirely.
Get-FolderSize | Export-Csv "test.csv" -Encoding UTF8
Which will by default show 2 size columns one for MB and another for GB.

yeah same issue with folders that have square brackets " [ ] " in the name. I wonder why that is. I could rename them but that seems like it shouldnt be needed if you know what I mean. I would assume its a thing with Get-FolderSize rather than the pipe to Export-CSV, thoughts?

@TheIdiotYouYellat another side request if you happen to know. Looking for a powershell command to Grab Disk info, specifically Total size, Used Size, and Free Size. This could also be done via partition and the drives only have a single partition.

Get-PSDrive

Square brackets are the index operator in powershell. You could try to get around this by putting the folder name/path in “double quotes”

Not exactly what you asked for but LazyWinAdmin has a bunch of functions for different info that you could use in other scripts.