Function Get-FolderSize{
Param(
[Parameter( Mandatory=$True )]
[String]$FolderPath
)
$dataCollection = @()
Get-ChildItem -force -Path $FolderPath -ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $.fullname -ErrorAction SilentlyContinue | % { $len += $.length }
$foldername = $_.fullname
$
f
o
l
d
e
r
s
i
z
e
=
′
0
:
N
2
′
−
f
(
foldersize= '{0:N2}' -f (
foldersize=′0:N2′−f(len / 1Gb)
$dataObject = New-Object PSObject
Add-Member -inputObject $dataObject -memberType NoteProperty -name “foldername” -value $foldername
Add-Member -inputObject $dataObject -memberType NoteProperty -name “foldersizeGb” -value $foldersize
$dataColl += $dataObject
}
$dataCollection | Sort-Object -Property foldersizegb -Descending | Export-Csv C:\temp\cdrive.csv -NoTypeInformation
}