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

PowerShell 7运行应用报错:Get-ExecutionPolicy无法加载对应模块

PowerShell 7执行Get-ExecutionPolicy报错的解决方法

报错信息

Get-ExecutionPolicy: The 'Get-ExecutionPolicy' command was found in the module 'Microsoft.PowerShell.Security', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.

At line:1 char:1

  • Get-ExecutionPolicy;
  • CategoryInfo : ObjectNotFound: (Get-ExecutionPolicy:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

可能的报错原因

  • PowerShell 7和5.x的模块目录完全独立,核心模块Microsoft.PowerShell.Security本该默认内置,但如果PowerShell 7安装不完整、模块路径被篡改,就会出现加载失败。
  • 错误使用Install-Module命令:这个模块是PowerShell核心内置的,根本不在PowerShell Gallery上,所以执行Install-Module -Name Microsoft.PowerShell.Security肯定会报错,属于操作误区。
  • 系统权限限制:哪怕用管理员身份,UAC或者组策略可能阻止了核心模块的加载。
  • PowerShell 7的核心模块文件损坏,导致无法正常读取。

解决方法

  • 重新安装PowerShell 7
    卸载当前版本,下载最新稳定版完整安装。装完后执行Get-Module -ListAvailable Microsoft.PowerShell.Security,能列出模块信息就说明安装正常。
  • 重置模块路径
    在PowerShell 7里直接执行以下命令,恢复模块路径默认值:
    $env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') + ';' + [Environment]::GetEnvironmentVariable('PSModulePath', 'User')
    
    重启PowerShell 7后再试Get-ExecutionPolicy。
  • 检查安装目录权限
    找到PowerShell 7的安装目录(默认是C:\Program Files\PowerShell\7),右键→属性→安全,确认当前用户有“读取和执行”权限。
  • 手动指定路径导入模块
    先获取模块的实际路径:
    Get-Module -ListAvailable Microsoft.PowerShell.Security | Select-Object -ExpandProperty ModuleBase
    
    然后用拿到的路径手动导入,示例:
    Import-Module "C:\Program Files\PowerShell\7\Modules\Microsoft.PowerShell.Security"
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 11:27:30