Skip to content

Cloning an Instance

Heath Stewart edited this page Apr 13, 2018 · 2 revisions

You can clone the channel and component selection from an instance on one machine to use on another machine.

First create a script file or define a function with the following content:

#Requires -Version 3
#Requires -Module VSSetup

[CmdletBinding()]
param (
    [Parameter(Mandatory=$true, Position=0)]
    [string] $Path,

    [Parameter(Mandatory=$true, Position=1)]
    [string] $Destination
)

$instance = Get-VSSetupInstance $Path
if (!$instance) {
    throw "No instance found in $Path"
}

$name = $instance.DisplayName
if ($nickname = $instance.Properties['Nickname']) {
    $name += " ($nickname)"
}
write-verbose "Copying instance: $name"

$response = @{
    channelUri = $instance.ChannelUri
    channelId = $instance.ChannelId
    productId = $instance.Product.Id
    add = $($instance.Packages | where-object { @('Workload', 'Component') -contains $_.Type -and !$_.IsExtension } | select -expand Id)
    addProductLang = @('en-US')
}

$languages = $instance.Packages | where-object { $_.Language } | group-object Language -noelement
if ($languages.Count) {
    write-verbose 'Overriding default language with installed languages'
    $response.addProductLang = $languages | select-object Name -unique
}

# None of this information should contain Unicode characters; need UTF-8 without BOM.
write-verbose "Writing response file to $Destination"
$response | convertto-json | set-content $Destination -encoding ASCII

Run this command with the path to the instance you want to clone and the location of the response file to create:

Copy-VSSetupInstance "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise" $env:TEMP\response.json

You'll use this response file in the following steps.

Warning: cloning selected components this way means that if you later remove workloads or components for the new instance, not all child components may be removed.

Installing from the web

To install from the web onto individual machine:

  1. Download the Visual Studio bootstrapper (any edition will do).
  2. Copy "$env:TEMP\response.json" ("%TEMP%\response.json") to your target machine, e.g. in its own "$env:TEMP".
  3. Assuming the downloaded location "~\Downloads\vs_enterprise.exe", run the following on another machine:
    ~\Downloads\vs_enterprise.exe --in $env:TEMP\response.json
  4. Choose an install location and make any other selections you want.
  5. Click Install.

Installing from a layout

To add or update a response file for a layout:

  1. Review how to define settings in a response file.
  2. Modify the "response.json" file to merge the content of "$env:TEMP\response.json" - mainly the add JSON property.
  3. Deploy the layout.
Clone this wiki locally