2013-01-23 17 views
6

Ho ottenuto uno script seguente da Internet, quando ho provato a eseguirlo mi dà un errore.Errore di decompressione Powershell

#script 
#unzip folder 

$shell_app = new-object -com shell.application 
$filename = "test.zip" 
$zip_file = $shell_app.namespace("C:\temp\$filename") 

#set the destination directory for the extracts 
$destination = $shell_app.namespace("C:\temp\zipfiles") 

#unzip the file 
$destination.Copyhere($zip_file.items()) 

--- Messaggio di errore

You cannot call a method on a null-valued expression. 
At line:1 char:22 
+ $destination.Copyhere <<<< ($zip_file.items()) 
    + CategoryInfo   : InvalidOperation: (Copyhere:String) [], RuntimeException 
    + FullyQualifiedErrorId : InvokeMethodOnNull 
+3

Controllare $ destinazione, probabilmente è nullo ad es. '$ destination -eq $ null' restituisce True. –

risposta

7

è necessario creare la "c: \ temp \ zipfiles" cartella prima di impostare la variabile $ destinazione, questo tipo di strada sciatta ma sarà fare il lavoro :)

#script 
#unzip folder 

$shell_app = new-object -com shell.application 
$filename = "test.zip" 
$zip_file = $shell_app.namespace("C:\temp\$filename") 

#set the destination directory for the extracts 
if (!(Test-Path "C:\temp\zipfiles\")) { 
    mkdir C:\temp\zipfiles 
} 
$destination = $shell_app.namespace("C:\temp\zipfiles") 

#unzip the file 
$destination.Copyhere($zip_file.items()) 
+0

Grazie, ha funzionato. – Lakhae