2013-01-23 4 views
6

Ich habe ein folgendes Skript aus dem Internet, als ich versuchte, es auszuführen gibt mir einen Fehler.Powershell unzip Fehler

#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()) 

--- Fehlermeldung

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

Überprüfen Sie $ Ziel, es ist wahrscheinlich null zB '$ destination -eq $ null' gibt True zurück. –

Antwort

7

Sie müssen die "c: \ temp \ ZipFiles" erstellen Ordner, bevor Sie die $ Zielvariable gesetzt, diese Art von schlampig Weg, aber es wird mach den Job :)

#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

Danke, es hat funktioniert. – Lakhae

Verwandte Themen