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

PowerShell执行vswhere.exe报错:Unexpected token '-property'问题求助

在PowerShell中执行vswhere命令获取VS版本信息报错的解决方法

问题

尝试通过PowerShell获取Microsoft Visual Studio组件版本信息,使用命令:

"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property catalog_productDisplayVersion

该命令在CMD中可正常运行,但在PowerShell中执行时抛出以下解析错误:

At line:1 char:72
-... x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property catalog ...
~~~~~~~~~
Unexpected token '-property' in expression or statement.
At line:1 char:82
-... Studio\Installer\vswhere.exe" -property catalog_productDisplayVersion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'catalog_productDisplayVersion' in expression or statement.

  • CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
  • FullyQualifiedErrorId : UnexpectedToken

原因

PowerShell的语法解析逻辑与CMD不同:当用双引号包裹可执行文件路径后,后续的参数会被视为字符串的一部分,而非独立的命令参数,导致解析失败。

解决方法

方法1:使用调用操作符&

通过&(调用操作符)执行带路径的可执行文件,PowerShell会正确识别后续的参数:

& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property catalog_productDisplayVersion

方法2:改用单引号包裹路径

将可执行文件路径用单引号包裹,PowerShell会将其识别为可执行文件路径,后续参数正常解析:

'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' -property catalog_productDisplayVersion

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 19:16:02