我如何 运行 7zip 通过 powershell 提取 .rar 文件夹?

How do i run 7zip through powershell to extract a .rar folder?

我已经用谷歌搜索过了,但我就是找不到直接的正确答案。我想添加一种方法来提取 .rar 文件夹,无论是通过 winRAR 还是 7zip 到我的 powershell 脚本中,这样我就可以自动化它。我知道 powershell 有一个内置的 zip 文件功能,但不幸的是我的老板不会使用 zip,因为它不像 .rar 那样压缩东西。

7z e archive.zip

将存档 archive.zip 中的所有文件提取到当前目录。

Here are the commands and here 是命令行语法的指南

我相信'e'是为了提取(也有x,所以根据需要调整):

$SourceFile="blahblah.zip"
$Destination="C:\temp\myfolder"
&$zipExe x $SourceFile "-o$Destination" -y 

应该可以。 $zipExe 将是您通往 7zip 的路径。例如:

$zipExe = join-path ${env:ProgramFiles(x86)} '7-zipz.exe'
if (-not (test-path $zipExe)) {
    $zipExe = join-path ${env:ProgramW6432} '7-zipz.exe'
    if (-not (test-path $zipExe)) {
         '7-zip does not exist on this system.'
    }
}