Эта функция может сделать это:
function Get-UncompressedZipFileSize {
param (
$Path
)
$shell = New-Object -ComObject shell.application
$zip = $shell.NameSpace($Path)
$size = 0
foreach ($item in $zip.items()) {
if ($item.IsFolder) {
$size += Get-UncompressedZipFileSize -Path $item.Path
} else {
$size += $item.size
}
}
# It might be a good idea to dispose the COM object now explicitly, see comments below
[System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$shell) | Out-Null
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
return $size
}
Пример использования:
$zipFiles = Get-ChildItem -Path "C:\path\to\zips" -Include *.zip -Recurse
foreach ($zipFile in $zipFiles) {
Select-Object @{n='FullName'; e={$zipFile.FullName}}, @{n='Size'; e={Get-UncompressedZipFileSize -Path $zipFile.FullName}} -InputObject ''
}
Пример вывода:
FullName Size
-------- ----
C:\test1.zip 4334400
C:\test2.zip 8668800
C:\test3.zip 8668800