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

如何在CMD中带参数运行PowerShell脚本?含空格路径如何处理?

在CMD中执行dotnet-install.ps1的正确命令

基础命令写法

要在CMD中执行PowerShell脚本,必须通过powershell.exe调用,同时解决权限与参数解析问题:

powershell.exe -ExecutionPolicy Bypass -File dotnet-install.ps1 -Channel 7.0 -Runtime aspnetcore
  • -ExecutionPolicy Bypass:临时绕过PowerShell的默认脚本执行策略,直接解决UnauthorizedAccess错误(默认策略会拦截未签名脚本运行)
  • -File:明确指定目标PowerShell脚本文件,确保后续的-Channel、-Runtime等参数能被PowerShell正确识别,解决MissingArgument错误

脚本路径含空格的处理

如果脚本所在路径包含空格,需将完整路径用双引号包裹:

powershell.exe -ExecutionPolicy Bypass -File "E:\Program Files\dotnet scripts\dotnet-install.ps1" -Channel 7.0 -Runtime aspnetcore

注意:双引号必须包裹整个脚本路径,不能仅针对空格部分拆分,否则CMD会出现路径解析错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 22:55:55