You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell 7中Expand-Archive报错:找不到ZipFileExtensions类型

在PowerShell 7中解决Expand-Archive报错Unable to find type [System.IO.Compression.ZipFileExtensions]的方案

你遇到的问题核心是:PowerShell 7基于.NET Core/.NET 5+运行时,而ZipFileExtensions是.NET Framework专属类型,因此无法通过Add-Type加载;但Expand-Archive本身是支持PowerShell 7的,问题出在模块或运行环境上,以下是几种可行的解决办法:

1. 修复或更新Microsoft.PowerShell.Archive模块

你的Expand-Archive来自版本1.2.5的Microsoft.PowerShell.Archive模块,该版本兼容PowerShell 7,但可能存在安装损坏或版本兼容问题:

  • 卸载现有模块:
    Uninstall-Module -Name Microsoft.PowerShell.Archive -Force
    
  • 重新安装最新兼容版本:
    Install-Module -Name Microsoft.PowerShell.Archive -Force -SkipPublisherCheck
    
  • 强制重新导入模块:
    Import-Module Microsoft.PowerShell.Archive -Force
    

完成后重试Expand-Archive,多数情况下可解决问题。

2. 直接调用.NET Core原生压缩API

绕开PowerShell模块,直接使用.NET Core内置的System.IO.Compression.ZipFile类执行解压,该类型在PowerShell 7中无需额外加载即可使用:

# 替换为你的ZIP文件路径和目标解压目录
$zipFilePath = "C:\example\archive.zip"
$extractDestination = "C:\example\extracted"

# 执行解压
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFilePath, $extractDestination)

此方法完全依赖.NET Core原生功能,稳定性更高,不受PowerShell模块问题影响。

3. 检查PowerShell 7与.NET Runtime的完整性

若上述方法无效,可能是PowerShell 7安装不完整或依赖的.NET Runtime缺失组件:

  • 卸载当前PowerShell 7,从官方渠道下载包含.NET Runtime的完整安装包重新安装,确保安装过程无报错。
  • 修复已安装的.NET Runtime:打开「控制面板→程序和功能」,找到对应版本的.NET Runtime,选择「更改→修复」。

4. 排查模块加载异常

若模块重新安装后仍无法使用,可通过 verbose 模式查看加载日志定位问题:

Import-Module Microsoft.PowerShell.Archive -Verbose

根据输出的错误信息(如权限不足、文件损坏等)针对性处理。


内容的提问来源于stack exchange,提问作者David W

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 17:01:10