PowerShell 执行命令提示 ps1 cannot be loaded because running scripts is disabled on this system

2026-11-29 13:37:00
丁国栋
原创 59
摘要:PowerShell 执行命令提示 `ps1 cannot be loaded because running scripts is disabled on this system` 是因为执行策略不允许执行脚本,需要执行:`Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted` 允许当前用户不受限制执行脚本。
导出 Markdown ZIP 包含 Markdown 原文。

PowerShell 执行命令提示 ps1 cannot be loaded because running scripts is disabled on this system 是因为执行策略不允许执行脚本,像npm这些在Windows平台里执行的文件也是由PowerShell脚本写或者有关的。

需要执行:Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted 允许当前用户不受限制执行脚本。

可以通过命令确认 Get-ExecutionPolicy -Scope CurrentUser 执行策略。

PS C:\Users\dgden> Get-ExecutionPolicy -Scope CurrentUser
Unrestricted
PS C:\Users\dgden>

原来的记录:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\dgden> fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
PS C:\Users\dgden> fnm install --use 26
Installing Node v26.13.1 (x64)
00:00:09 39.26 MiB/39.26 MiB (4.15 MiB/s, 0s)
Using Node v26.13.1
PS C:\Users\dgden> node -v
v26.13.1
PS C:\Users\dgden> npm -v
npm : File C:\Users\dgden\AppData\Local\fnm_multishells\14740_1795918229296\npm.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ npm -v
+ ~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\dgden> npx @deepseek-ai/dsh web
npx : File C:\Users\dgden\AppData\Local\fnm_multishells\14740_1795918229296\npx.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ npx @deepseek-ai/dsh web
+ ~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\dgden> Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
PS C:\Users\dgden> npm -v
11.20.0
PS C:\Users\dgden> npx @deepseek-ai/dsh web
Need to install the following packages:
@deepseek-ai/dsh@0.2.2-rc.5
Ok to proceed? (y) y
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
dsh web: http://127.0.0.1:3080/?token=aAcC6IZCTR3-6GA6kOtxm1AZWUFJv5zdUhJpwpzu6SU
dsh web: opening the default browser; pass --no-open to disable
[llm-deepseek-api-key] model listing from https://api.deepseek.com/models loaded 2 model(s), skipped 0 row(s)
PS C:\Users\dgden>

还没有评论,来做第一个吧!

称呼
邮箱
博客分类