一、错误现象
在 PowerShell 中运行 MAS(Microsoft Activation Scripts)的一键命令时,出现以下错误:
irm : 无法识别该URI前缀。
所在位置 行:1 字符: 1
+ irm htps://get. activated. win | iex
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod],NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomainsNotSupported,Microsoft.PowerShell.Commands.InvokeRestMethodCommand或者在较新版本的 PowerShell 中报错:
Invoke-RestMethod: Cannot determine the URI scheme. The URI prefix is not recognized.二、错误原因
这个错误有两种常见原因:
原因一:命令中包含了不可见字符或空格(最常见)
MAS 官方命令是:
irm https://get.activated.win | iex但有时从网页或文档复制时,URL 中混入了零宽空格(Zero-Width Space)、全角字符或多余空格,导致 PowerShell 无法解析 URI。
例如,下面这些写法全部都会报错:
# ❌ 域名中间有空格
irm https://get. activated.win | iex
# ❌ 协议写错(少写 s)
irm http://get.activated.win | iex
# ❌ 全角字符(:// 是中文符号)
irm https://get.activated.win | iex
# ❌ 复制时混入零宽空格(肉眼看不出来)
irm https://get.activated.win | iex原因二:PowerShell 版本过低(Windows PowerShell 5.1 及以下)
旧版 PowerShell 的 Invoke-RestMethod 在某些系统配置下对 HTTPS 支持不完整,会出现 URI 解析失败。
原因三:IE 增强安全配置(Windows Server)
在 Windows Server 上,默认启用了 IE 增强安全配置(IE Enhanced Security Configuration),它会阻止 PowerShell Web Cmdlet 访问任何未列入白名单的 URL。
三、解决方案
方案 1:手动输入命令(推荐)
不要复制粘贴,直接在 PowerShell 中手动输入:
irm https://get.activated.win | iex确认 URL 中没有任何空格,协议是 https(不是 http),域名是 get.activated.win(中间无空格)。
方案 2:先测试 URL 是否可达
先单独测试 irm 能否正常下载:
irm https://get.activated.win -UseBasicParsing如果正常,会返回脚本内容(一堆 PowerShell 代码)。如果仍然报错,说明网络或 PowerShell 版本有问题。
使用 -UseBasicParsing 参数可以绕过 IE 引擎,在 Server 系统或 PowerShell 7 上更稳定。
方案 3:升级到 PowerShell 7
Windows 自带的 PowerShell 5.1 功能有限,建议安装 PowerShell 7:
# 方法一:winget 安装
winget install --id Microsoft.Powershell --source winget
# 方法二:直接下载
# https://github.com/PowerShell/PowerShell/releases安装后打开 PowerShell 7(pwsh.exe) 再运行命令:
pwsh
irm https://get.activated.win | iex方案 4:先下载到本地再执行
如果 irm | iex 管道方式不行,可以分两步执行:
# 步骤 1:下载脚本到本地
Invoke-WebRequest -Uri "https://get.activated.win" -OutFile "$env:TEMP\MAS.ps1" -UseBasicParsing
# 步骤 2:查看下载的内容(确认不是 HTML 错误页面)
Get-Content "$env:TEMP\MAS.ps1" -Head 10
# 步骤 3:执行脚本
& "$env:TEMP\MAS.ps1"这种方法可以绕过 irm 的 URI 解析问题,也能看清下载过程中的网络错误。
方案 5:设置 TLS 版本
某些旧系统默认使用的 TLS 版本过低,被服务器拒绝:
# 强制使用 TLS 1.2(在运行命令前执行)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# 或同时启用多个版本
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
# 再运行
irm https://get.activated.win | iex方案 6:关闭 IE 增强安全配置(Windows Server)
如果是在 Windows Server 上运行:
- 打开 服务器管理器
- 点击 本地服务器
- 找到 IE 增强的安全配置,点击 启用
- 选择 关闭(对管理员和用户都关闭)
- 重启 PowerShell 再试
或者在 PowerShell 中直接修改注册表:
# 关闭管理员和用户的 IE ESC
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0 -ErrorAction SilentlyContinue
# 重启 PowerShell 生效方案 7:设置 PowerShell 执行策略
如果 irm 下载成功但 iex 执行时报权限错误,需要设置执行策略:
# 查看当前执行策略
Get-ExecutionPolicy
# 设置为 RemoteSigned(允许运行本地脚本和已签名的远程脚本)
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
# 再执行
irm https://get.activated.win | iex注意:执行策略改完后,如果需要恢复,运行
Set-ExecutionPolicy Restricted -Scope CurrentUser -Force。
四、各方案适用场景速查
| 场景 | 推荐方案 |
|---|---|
| 复制命令时报错 | 方案 1:手动输入 |
| Windows 7 / 8 | 方案 3:升级 PowerShell 7 + 方案 5:设置 TLS |
| Windows Server | 方案 2 + 方案 6:关闭 IE ESC |
| 公司网络受限 | 方案 4:下载到本地执行 |
| PowerShell 5.1 | 方案 2:加 -UseBasicParsing |
| 任何不确定的情况 | 方案 2 → 方案 3 → 方案 4 逐步尝试 |
五、验证是否正常
成功执行后,MAS 界面会显示:
===========================================================================
Microsoft Activation Scripts (MAS)
===========================================================================如果看到这个界面,说明 irm | iex 已成功运行,按提示选择激活方式即可。
六、常见误区
❌ 以为网址打不开
get.activated.win 返回的是 PowerShell 脚本内容,不是 HTML 网页。用浏览器打开可能显示空白或乱码,这是正常的。
❌ 手动拼写域名
域名是 get.activated.win,不是:
get.activatedwin.comgetactivated.winmassgrave.dev(这是帮助页面)
❌ 使用 HTTP(非 HTTPS)
MAS 服务器强制 HTTPS,使用 http:// 会被重定向或拒绝连接。
七、总结
"无法识别该 URI 前缀"这个错误 90% 的原因就是命令中有看不见的空格或特殊字符。
最佳做法:
- 手动输入命令,不复制粘贴
- 如果仍不行,加
-UseBasicParsing参数 - 再不行,升级到 PowerShell 7
- 最后保底:先下载到本地再执行
最稳妥的一行命令(兼容所有情况):
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri "https://get.activated.win" -OutFile "$env:TEMP\MAS.ps1" -UseBasicParsing; & "$env:TEMP\MAS.ps1"