小编Spi*_*776的帖子

我想使用powershell在temp中的给定目录中提取所有.zip文件

我编写了以下代码来将.zip文件解压缩到temp:

function Expand-ZIPFile($file, $destination)
{
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($file)
    foreach ($item in $zip.items()) {
       $shell.Namespace($destination).copyhere($item)
    }
}

Expand-ZIPFile -file "*.zip" -destination "C:\temp\CAP"
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

PS C:\Users\v-kamoti\Desktop\CAP> function Expand-ZIPFile($file, $destination)
{
   $shell = new-object -com shell.application
   $zip = $shell.NameSpace($file)
   foreach ($item in $zip.items()) {
      $shell.Namespace($destination).copyhere($item)
   }
}

Expand-ZIPFile -file "*.zip" -destination "C:\temp\CAP"
You cannot call a method on a null-valued expression.
At line:5 char:19
+  foreach($item in $zip.items())
+                   ~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
Run Code Online (Sandbox Code Playgroud)

powershell unzip

4
推荐指数
2
解决办法
8554
查看次数

标签 统计

powershell ×1

unzip ×1