Skip to content

Selecting an Instance

Heath Stewart edited this page Feb 6, 2017 · 2 revisions

A product instance contains a lot of information about what is installed and where it is installed. By default, the Select-VSSetupInstance cmdlet queries Visual Studio products but other products can be selected.

Note that the following examples specify the line continuation character ``` to correctly wrap commands, but this is unnecessary when working interactively in PowerShell: just type everything on one command if you wish.

Selecting the right instance

In many cases you may need to select the latest instance of a particular version.

Get-VSSetupInstance `
  | Select-VSSetupInstance -Version '[15.0,16.0)' -Latest

This would select the latest version of any edition of Visual Studio 2017 - Community, Professional, or Enterprise. You can also select instances that contain one or more workloads or components, such as the Visual C++ desktop workload.

Get-VSSetupInstance `
  | Select-VSSetupInstance -Require Microsoft.VisualStudio.Workload.NativeDesktop -Latest `
  | Select-Object -ExpandProperty InstallationPath

The previous example extracts just the installation path to with as you need.

Selecting other products

You can also use the same query capabilities for other products such as Build Tools.

Get-VSSetupInstance `
  | Select-VSSetupInstance -Product Microsoft.VisualStudio.Product.BuildTools -Latest