Unexpected token '-property' in expression or statement

1.1k views Asked by At

Hi everyone I am trying to fetch the version of Microsoft Visual Studio components from powershell I tried "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property catalog_productDisplayVersion command But its working only on 'command Prompt'

I ran this command, "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property catalog_productDisplayVersion

output: 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

1

There are 1 answers

3
Gabriel Luci On BEST ANSWER

Prefix the command with the PowerShell "Call Operator", which is an ampersand:

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

It prevents PowerShell from trying to parse the string.