powershell - 如何在 Powershell 中列出 .zip 文件的内容?

标签 powershell

我有超过 1000 个 .zip 文件,我需要通过这些文件来查找 .pst 文件。这些 .zip 文件由 VMware Horizo​​n 的组件使用,因此无法先解压缩它们。

我试过使用 dir 甚至 dir -force,但这些不会自动深入到 zip 文件的内容中。

powershell 或 Windows 命令提示符中是否有内置方法可以打印 .zip 文件的内容,而无需我先解压缩文件夹?

最佳答案

使用 .Net 框架中的 ZipFile 类。要列出存档文件中的条目,您可以在 Powershell 中像这样使用它:

[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')

foreach($sourceFile in (Get-ChildItem -filter '*.zip'))
{
    [IO.Compression.ZipFile]::OpenRead($sourceFile.FullName).Entries.FullName |
        %{ "$sourcefile`:$_" }
}

或者,如果你有 PowerShell 社区扩展,你可以使用它的 Read-Archive小命令。

https://archive.codeplex.com/?p=pscx

关于powershell - 如何在 Powershell 中列出 .zip 文件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57117870/

相关文章:

powershell - Powershell管道中的错误处理

regex - Powershell开关和正则表达式

powershell - "You cannot call a method on a null-valued expression"在代码中使用参数时

powershell - PowerShell WebRequest:发送中发生意外错误

powershell - 在Windows命令提示符/PowerShell中下载大文件

.net - 使用PowerShell将文件上传到FTP,文件名在GB2312中,而不是UTF-8

powershell - PowerShell中的包装函数: Pass remaining parameters

powershell - 如何在Powershell中使用Java命令

Powershell:内联表达式中的双引号

azure - 为什么azure子网没有subnet.id参数