Powershell ';调用表达式';删除双引号

Powershell ';调用表达式';删除双引号,powershell,Powershell,我有一个包含ZIP文件的目录结构,我想用一个脚本来提取它们 到目前为止,我的剧本是: $7zexe = "c:\bin\7za.exe" $arg = "" Get-ChildItem -Recurse -Include *.zip | ForEach-Object { $argout = $_.Directory.Name $arg = " e `"$_`" -o`"$argout`"" $cmdline = $7zexe, $arg -join "" $cmdline Inv

我有一个包含ZIP文件的目录结构,我想用一个脚本来提取它们

到目前为止,我的剧本是:

$7zexe = "c:\bin\7za.exe"
$arg = ""
Get-ChildItem -Recurse -Include *.zip |
ForEach-Object { $argout = $_.Directory.Name
  $arg = " e `"$_`" -o`"$argout`""
  $cmdline = $7zexe, $arg -join ""
  $cmdline
  Invoke-Expression -command  "$cmdline "
}
但是我得到了以下错误

c:\bin\7za.exe e "E:\tmp\the folder\the sub folder\my_big_file.zip" -o"the sub folder"
Invoke-Expression : The string starting:
At line:1 char:86
 + c:\bin\7za.exe e "E:\tmp\the folder\the sub folder\my_big_file.zip" -o"the sub folder <<<< "
 is missing the terminator: ".
At x:\mydocs\testscript.ps1:9 char:18
+ Invoke-Expression <<<<  -command  "$cmdline "
    + CategoryInfo          : ParserError: ( :String) [Invoke-Expression], IncompleteParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString,Microsoft.PowerShell.Commands.InvokeExpressionCommand

尝试将-o放在引号内:

$7zexe = "c:\bin\7za.exe"
$arg = ""
Get-ChildItem -recurse -Include *.zip | 
ForEach-Object { $argout = $_.Directory.FullName
  write-host -ForegroundColor Green $argout
  $arg = " e `"$_`" `"-o$argout`""
  $cmdline = $7zexe, $arg -join ""
  $cmdline
  Invoke-Expression -command  "$cmdline "
}

旁注:要确保深度嵌套zip文件的内容解压缩到正确的目录,我认为您应该使用包含目录的fullname属性。

尝试将-o放在引号内:

$7zexe = "c:\bin\7za.exe"
$arg = ""
Get-ChildItem -recurse -Include *.zip | 
ForEach-Object { $argout = $_.Directory.FullName
  write-host -ForegroundColor Green $argout
  $arg = " e `"$_`" `"-o$argout`""
  $cmdline = $7zexe, $arg -join ""
  $cmdline
  Invoke-Expression -command  "$cmdline "
}

侧注:为了确保深度嵌套的zip文件的内容解压缩到正确的目录,我认为您应该使用包含目录的全名属性。

谢谢,它看起来是解决方案,但我在清理环境时仍然遇到一些问题(不知何故,powershell确信&arg是一个数组????添加
[string]$arg=“
解决了这个问题,但看起来是解决方案,但我在清理环境时仍然遇到一些问题(不知何故,powershell确信&arg是一个数组???添加
[string]$arg=“”
解决了此问题,另请参见。另请参见。