計量文件夾大小

##Using .com objects
function DirWithSize ($path=$PWD)
{
    $fs=New-Object -com scripting.filesystemobject
    Get-ChildItem $path|Format-Table -AutoSize Mode,LastWriteTime,Name,
    @{ Label="Lenght(KB)";alignment="Left";Expression={
        if($_.PSIsContainer){$fs.GetFolder($_.Fullname).Size/1KB}
        else
            {$_.length/1KB}
        }
    }
}
##Using measure count
function DirWithSize ($path=$pwd)
{
    ls $path |ft -au mode,lastwritetime,name,
    @{ Label="lenght(kb)";alignment="left";Expression={
        if($_.PsIsContainer){(ls $_.fullname -r -file|measure length -Sum).sum/1Kb}
        else
          {$_.length/1KB}
        }
    }
}

簡介:

  為什麼會有連個不同的例子呢? 其實如果你在C盤的更目錄執行這兩個函數你就會發現

  

原文地址:https://www.cnblogs.com/feiyucha/p/12078143.html