2013-01-23 26 views
6

インターネットから次のスクリプトを取得しましたが、実行しようとするとエラーが表示されます。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()) 

---あなたが作成する必要があるエラーメッセージ

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をチェックしてください、おそらくnullです'$ destination -eq $ null'はTrueを返します。 –

答えて

7

「C:\ TEMP \ zipファイル」あなたは$先変数を設定する前に、フォルダを、 ずさんな方法のこの種が、それはします仕事をしなさい:

#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