PARAM (
[string] $SourceZipPath, #= "X:\Somepath\Full\Of\Zipfiles",
[string] $DestinationPath #= "X:\Somepath\to\extract\to"
)
$ErrorActionPreference = "Stop"
$Shell = New-Object -com Shell.Application
$ZipFiles = Get-Childitem $SourceZipPath -Recurse | % {& "C:\Program Files\7-Zip\7z.exe" "x" $_.fullname "-o" $DestinationPath} -Include *.ZIP
当我尝试运行时,请在上面的代码中建议更正,但会出现以下错误:
ForEach-Object : Cannot bind parameter 'RemainingScripts'. Cannot convert the "-Include" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
At C:\Users\******\Desktop\Zip****Extractor-v0.6.ps1:11 char:53
-Recurse | % {& "C:\Program Files\7-Zip\7z.exe" "x" "-o" $Destinatio ...
+ CategoryInfo:InvalidArgument:(:)[ForEach-Object], ParentContainsErrorRecordException
+FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand
答案 0 :(得分:0)
作为4c74356b41 mentioned,您必须将-Include
参数放入Get-ChildItem
cmdlet:
Param
(
[string] $SourceZipPath, #= "X:\Somepath\Full\Of\Zipfiles",
[string] $DestinationPath #= "X:\Somepath\to\extract\to"
)
$ErrorActionPreference = "Stop"
$Shell = New-Object -com Shell.Application
$ZipFiles = Get-Childitem $SourceZipPath -Include *.ZIP -Recurse |
ForEach-Object {
& "C:\Program Files\7-Zip\7z.exe" "x" $_.fullname "-o" $DestinationPath
}