I am trying to write a script using powershell to get folder / file size as mentioned below -
$StartFolder = "D:\" $Output = "C:\Temp\test-d.csv" Add-Content -Value "Folder Path|Size" -path $Output $colItems = (Get-ChildItem $startFolder -Recurse | Measure-Object -property length -sum) "$StartFolder -- " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB" # | out-file $Output $colItems = (Get-ChildItem $startFolder -recurse | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object) foreach ($i in $colItems) { $subFolderItems = (Get-ChildItem $i.FullName -Recurse | Measure-Object -property length -sum) $i.FullName + "|" + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB" | out-file $Output -Append }
I am getting error as mentioned below…
Measure-Object : The property "length" cannot be found in the input for any objects. At line:12 char:65 + $subFolderItems = (Get-ChildItem $i.FullName -Recurse | Measure-Object - ... + + CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand Measure-Object : The property "length" cannot be found in the input for any objects. At line:12 char:65 + $subFolderItems = (Get-ChildItem $i.FullName -Recurse | Measure-Object - ... + + CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand }
Can you pls assist me in that & also when I target C: drive I am getting access denied in some system files -
Get-ChildItem : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied. At line:12 char:28 + $subFolderItems = (Get-ChildItem $i.FullName -Recurse | Measure-Object - ... + + CategoryInfo : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildItem], UnauthorizedAccessException + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand