2013-01-23 8 views
6

Mam następujący skrypt z Internetu, kiedy próbowałem go uruchomić, daje mi błąd.Błąd rozpakowania 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()) 

--- Komunikat o błędzie

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

Sprawdź cel $, prawdopodobnie jest to wartość pusta, np. '$ destination -q $ null' zwraca True. –

Odpowiedz

7

trzeba stworzyć "c: \ temp \ zipfiles" Folder przed ustawieniem zmiennej $ docelowy, tego rodzaju niechlujny sposób, ale będzie wykonuj zadanie :)

#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

Dzięki, zadziałało. – Lakhae

Powiązane problemy