嗨大家我遵循了这个指南:
http://www.howtogeek.com/tips/how-to-extract-zip-files-using-powershell/
但我一直收到空值错误。
您无法在空值表达式上调用方法。 在行:11 char:1 + $ shell.Namespace($ destination).copyhere($ item)
我不确定为什么我的目标变量已设置?下面是我的代码
function Expand-ZIPFile($file, $destination)
{
echo $file
echo $destination
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
echo $zip.Items()
foreach($item in $zip.items())
{
echo $item
$shell.Namespace($destination).copyhere($item)
}
}
Expand-ZIPFile “D:\temp\12102015.zip” “D:\temp\howtogeek”
和我的输出:
D:\temp\12102015.zip
D:\temp\howtogeek
Count Application Parent Verbs
----- ----------- ------ -----
2 System.__ComObject System.__ComObject
System.__ComObject System.__ComObject
You cannot call a method on a null-valued expression.
At line:11 char:1
+ $shell.Namespace($destination).copyhere($item)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
System.__ComObject System.__ComObject
You cannot call a method on a null-valued expression.
At line:11 char:1
+ $shell.Namespace($destination).copyhere($item)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
答案:
我的目标目录不存在:S