无法从命令提示符执行PowerShell脚本的问题求助
问题详情
- 操作场景:在管理员权限命令提示符中执行
test.ps1脚本 - 脚本内容:
echo "testing"
- 报错信息:
c:\run>powershell .\test.ps1 echo : The term 'Write-Output' is not recognized as the name of a cmdlet, function, script file, or operable program. out-lineoutput : Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer. Contact Microsoft Customer Support Services.
- CategoryInfo : ReadError: (:) [out-lineoutput], HostException
- FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.PowerShell.Commands.OutLineOutputCommand
c:\run>
- 环境配置:
- PowerShell路径已正常配置,
echo %PATH%输出包含C:\WINDOWS\System32\WindowsPowerShell\v1.0 - PowerShell执行策略:
- PowerShell路径已正常配置,
Scope ExecutionPolicy ----- --------------- MachinePolicy Unrestricted UserPolicy Undefined Process Undefined CurrentUser Unrestricted LocalMachine Undefined
解决方法
- 直接用管理员PowerShell执行:跳过CMD中转,打开管理员权限的PowerShell窗口,直接执行
.\test.ps1,避免CMD与PowerShell的权限交互冲突。 - 修正CMD中调用PowerShell的语法:在CMD里执行脚本时,使用完整命令格式:
powershell -ExecutionPolicy Bypass -File .\test.ps1,明确指定脚本文件并临时绕过执行策略限制。 - 重置PowerShell执行策略:以管理员身份执行
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine,统一本地机器的执行策略配置。 - 修复系统核心组件:执行
sfc /scannow扫描并修复系统文件,解决Write-Output这类核心cmdlet无法识别的问题,完成后重启系统再测试。
内容的提问来源于stack exchange,提问作者suthan
相关产品推荐
相关产品推荐

