2013-01-23 10 views
6

मैं इंटरनेट से एक निम्न स्क्रिप्ट मिल गया, जब मैं यह मुझे एक त्रुटि देता है भागने की कोशिश की।Powershell unzip त्रुटि

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

--- त्रुटि संदेश

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

$ गंतव्य की जांच करें, यह शायद शून्य है '$ destination -eq $ null' सही लौटाता है। –

उत्तर

7

आप "c: \ अस्थायी \ zipfiles" बनाने की जरूरत फ़ोल्डर इससे पहले कि आप $ गंतव्य चर, लापरवाह तरह से इस तरह का सेट, लेकिन यह होगा नौकरी करें :)

#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

धन्यवाद, यह काम किया। – Lakhae