如何使用 Powershell 2.0 版解压缩 Zip 文件? [英] How to unzip a Zip File with Powershell Version 2.0?

查看:59
本文介绍了如何使用 Powershell 2.0 版解压缩 Zip 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这适用于 PowerShell 4.0 或更高版本.但是在 PowerShell 2.0 版中,Add-Type 是不可能的(类型不存在).

This works for me with PowerShell version 4.0 or higher. But at PowerShell version 2.0 the Add-Type isn't possible (type doesn't exist).

function unzip {
    Add-Type -Assembly "system.io.compression.filesystem"

    [io.compression.zipfile]::ExtractToDirectory("SOURCEPATH\ZIPNAME", "DESTINATIONPATH")
}

推荐答案

function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}

这通过 Shell.Application 对象利用了 Windows 的内置 zip 文件支持.要使用它,请运行以下命令.

This leverages Windows's built in zip file support, via the Shell.Application object. To use this, run the following.

>Expand-ZipFile .\Myzip.zip -destination c:\temp\files

来源:http://www.howtogeek.com/tips/how-to-extract-zip-files-using-powershell/

这篇关于如何使用 Powershell 2.0 版解压缩 Zip 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆