Скрипт создает Excel файл, куда выводит результат.
# Size of folder including subfolders $startFolder = read-host -Prompt "enter full path" #c:\temp if(Test-Path -Path $startFolder) { $length = 0 $a = New-Object -comobject Excel.Application $a.visible = $True $b = $a.Workbooks.Add() $c = $b.Worksheets.Item(1) $c.Cells.Item(1,1) = "Name" $c.Cells.Item(1,2) = "Size (MB)" $d = $c.UsedRange $d.Font.Bold = $True $intRow = 3 $colItems = (Get-ChildItem $startFolder | Measure-Object -property length -sum) $length += $colItems.sum $c.Cells.Item(2,1) = $startFolder $c.Cells.Item(2,2) = "{0:N2}" -f ($colItems.sum / 1MB) $colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object) foreach ($i in $colItems) { $objFSO = New-Object -com Scripting.FileSystemObject $c.Cells.Item($intRow,1) = $i.FullName $c.Cells.Item($intRow,2) = "{0:N2}" -f (($objFSO.GetFolder($i.FullName).Size) / 1MB) $length += $objFSO.GetFolder($i.FullName).Size $intRow++ } $c.Cells.Item($intRow,1) = "Total Size" $c.Cells.Item($intRow,2) = "{0:N2}" -f ($length / 1MB) $d = $c.UsedRange $d.EntireColumn.AutoFit() } else { write-host "Folder $startFolder does NOT exist" -BackgroundColor Red }