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
}
2条答案
按热度按时间wfsdck301#
这个函数可以做到这一点:
示例用法:
示例输出:
g6ll5ycj2#
找到了另一种方法,不依赖于外部程序,不关心你是否禁用了zip文件夹查看文件资源管理器,是一个数量级的速度更快。
https://devblogs.microsoft.com/scripting/powertip-use-powershell-to-read-the-content-of-a-zip-file/