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

如何在Docker中安装PowerShell Community Extensions(PSCX)?

在Windows Server Core Docker容器中安装PSCX的解决方案

出现的NullReferenceException错误源于旧版本PowerShellGet(1.0.0.1)在非交互式环境下无法处理确认提示,导致调用ShouldContinue方法时触发空引用异常。解决方法是先更新PowerShellGet和NuGet组件,再安装PSCX,具体修改Dockerfile如下:

FROM mcr.microsoft.com/windows/servercore:ltsc2022

RUN powershell -Command \
    Set-ExecutionPolicy RemoteSigned -Force -Scope CurrentUser; \
    Register-PSRepository -Name PSGallery -InstallationPolicy Trusted; \
    Install-Module -Name PowerShellGet -Force -AllowClobber; \
    Import-Module PowerShellGet; \
    Install-Module Pscx -Scope CurrentUser -Confirm:$false -Force

关键步骤说明:

  • 设置执行策略:Set-ExecutionPolicy RemoteSigned允许运行已签名的PowerShell脚本,避免后续模块安装时的权限问题。
  • 信任PowerShell Gallery:将PSGallery设为受信任仓库,跳过安装时的仓库信任确认提示。
  • 更新PowerShellGet:旧版1.0.0.1存在非交互环境下的bug,更新到最新版本可修复该空引用异常,-AllowClobber允许覆盖现有模块文件。
  • 重新加载模块:确保后续安装命令使用的是刚更新的PowerShellGet版本。
  • 安装PSCX:通过-Confirm:$false和-Force完全跳过交互确认,适配Docker的非交互式构建环境。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 04:10:09