Using PowerShell 4.0, I try to get the size of several directories, and I get very conflicting results between what the windows tell me and what my code says.
This code:
$temp4 = ($folderInfo.rootFolder).fullname
$folderInfo.directories += Get-ChildItem -LiteralPath $temp4 -Recurse -Force -Directory
$folderInfo.directories += $folderInfo.rootFolder
foreach ($dir in $folderInfo.directories)
{
$temp3 = $dir.fullname
$temp2 = Get-ChildItem -LiteralPath $temp3 -Force
$temp = (Get-ChildItem -LiteralPath $dir.fullname -Force -File | Measure-Object -Property length -Sum -ErrorAction SilentlyContinue).Sum
$folderInfo.totalSize += $temp
}
return $folderInfo
if $folderInfo.rootFolder = D:\sample
then I get what I want but if $folderInfo.rootFolder = D:\[sample
then I get
Get-ChildItem: . : sample [sample C:\powershell\test.ps1: 55 char: 12 + $temp = (Get-ChildItem $dir.fullname -Force -File | Measure-Object -Property l... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: InvalidArgument: (:) [Get-ChildItem], ParameterBindingException + FullyQualifiedErrorId: GetDynamicParametersException, Microsoft.PowerShell.Commands.GetChildItemCommand
, D:\sample - , "[sample". , . $dir.pspath, $dir.fullname .
: , .
: .