티스토리 뷰

탐색 위치 변수

$searchPath = "c:\folders"



파일 갯수 구하기

(Get-ChildItem $searchPath -File -ErrorAction Ignore).Count


디렉토리 갯수

(Get-ChildItem $searchPath -Directory -ErrorAction Ignore).Count


모든 아이템 수

(Get-ChildItem $searchPath -ErrorAction Ignore).Count


하위 폴더 포함

(Get-ChildItem $searchPath -Recurse -ErrorAction Ignore).Count



폴더 사이즈 in MB

"{0:N2}" -f ((Get-ChildItem -path $searchPath -recurse | Measure-Object -property length -ErrorAction Ignore -sum).sum /1MB) + " MB"



리스트로 만들기


해쉬 테이블(?) 정의

$a=@{}


디렉토리를 탐색하면서 폴더의 사이즈를 반복적으로 대입

Get-ChildItem $sPath -Recurse -Directory -ErrorAction Ignore | Foreach { $a[$_.Fullname] = ((Get-ChildItem -path $_.Fullname -recurse | Measure-Object -property length -ErrorAction Ignore -sum).sum /1MB)}


정렬, 포맷팅, 출력

$a.GetEnumerator() | Sort Value -Descending | Format-List | Out-File d:\dir_size.txt



스크립트를 만들었다면 test.ps1 파일로 저장하고 아래 cmd를 이용해 실행

powershell -ExecutionPolicy ByPass -File test.ps1



예시) C:\에서 용량이 0.5GB가 넘고 파일 수가 1,000개 이상인 폴더를 평균 파일 크기의 역수로 정렬. 값이 클수록 파편화(?)가 크다는 뜻


$sPath = "c:\"
$a=@{}

Get-ChildItem $sPath -Recurse -Directory -ErrorAction Ignore | Foreach {
    $cntIt = (Get-ChildItem $_.Fullname -Recurse -ErrorAction Ignore).Count
    if( $cntIT -gt 1000 ) {
        $dirSZ = ((Get-ChildItem -path $_.Fullname -recurse | Measure-Object -property length -ErrorAction Ignore -sum ).sum /1MB)
        if( $dirSZ -gt 500 ) {
            $a[$_.Fullname] = $cntIt/$dirSZ
        }
    }
}
   
$a.GetEnumerator() | Sort Value -Descending | Format-List | Out-File c:\dir_analysis.txt

pause



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함