2016-12-05 205 views
1
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 

請當我試圖運行它提供了以下錯誤提示在上面的代碼修正:解壓縮.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 
+1

'-Include * .ZIP'應該是管之前,即'GET-Childitem $ SourceZipPath -Recurse -Include * .ZIP |' – 4c74356b41

回答

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 
    } 
+0

thanku這個幫助,但它顯示命令行錯誤: 開關太短: -o –

+0

@ShivaGupta -o和文件夾之間必須沒有空格。 – LotPings