-
-
Save jpluimers/e7c8e1f3999e2cb662d8010a0a982994 to your computer and use it in GitHub Desktop.
Chocolatey script to install Visual Studio 2017 from local NAS using offline installer. More info about how to create offline installer here: https://docs.microsoft.com/en-us/visualstudio/install/create-an-offline-installation-of-visual-studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## USAGE EXAMPLES | |
# installs CoreEditor (the IDE), ManagedDesktop (.NET framework applications), NetCoreTools (.NET core applications), NetWeb (ASP.NET) + active product using provided Product Key | |
# choco install visualstudio2017enterprise.pls -y --params "/Features:Microsoft.VisualStudio.Workload.CoreEditor,Microsoft.VisualStudio.Workload.ManagedDesktop,Microsoft.VisualStudio.Workload.NetCoreTools,Microsoft.VisualStudio.Workload.NetWeb /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" | |
# silent bare minimum installation with product key activation. The minimum installation contains only the Core Editor workload (Microsoft.VisualStudio.Workload.CoreEditor) | |
# choco install visualstudio2017enterprise.pls -y --params "/ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" | |
# silent bare minimum installation without product key activation | |
# choco install visualstudio2017enterprise.pls -y | |
# Parse input argument string into a hashtable | |
# Format: /InstallPath:path location /Features:Microsoft.VisualStudio.Workload.CoreEditor,Microsoft.VisualStudio.Workload.ManagedDesktop /ProductKey:AB-D1 | |
function Parse-Parameters ($s) | |
{ | |
$parameters = @{ } | |
if (!$s) | |
{ | |
Write-Debug "No package parameters." | |
return $parameters | |
} | |
Write-Debug "Package parameters: $s" | |
$s = ' ' + $s | |
[String[]] $kvpPrefix = @(" /") | |
$kvpDelimiter = ':' | |
$kvps = $s.Split($kvpPrefix, [System.StringSplitOptions]::RemoveEmptyEntries) | |
foreach ($kvp in $kvps) | |
{ | |
Write-Debug "Package parameter kvp: $kvp" | |
$delimiterIndex = $kvp.IndexOf($kvpDelimiter) | |
if (($delimiterIndex -le 0) -or ($delimiterIndex -ge ($kvp.Length - 1))) { continue } | |
$key = $kvp.Substring(0, $delimiterIndex).Trim().ToLower() | |
if ($key -eq '') { continue } | |
$value = $kvp.Substring($delimiterIndex + 1).Trim() | |
Write-Debug "Package parameter: key=$key, value=$value" | |
$parameters.Add($key, $value) | |
} | |
return $parameters | |
} | |
function Generate-Install-Arguments-String ($parameters) | |
{ | |
$s = "--includeRecommended --quiet --norestart --wait" | |
$s += " --addProductLang en-US --add Microsoft.VisualStudio.Workload.CoreEditor" | |
# --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetCoreTools --add Microsoft.VisualStudio.Workload.NetWeb | |
$features = $parameters['Features'] | |
if ($features) | |
{ | |
foreach ($f in $features.Split(',')) | |
{ | |
$s += " --add " | |
$s += $f.Trim() | |
} | |
} | |
$rpp = '& "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\StorePID.exe"' | |
$ip = $parameters['InstallPath'] | |
if ($ip) | |
{ | |
$s += " --installPath `"$ip`"" | |
$rpp = "& `"$($ip.Trim('\'))" + "\Common7\IDE\StorePID.exe`"" | |
} | |
$pk = $parameters['ProductKey'] | |
if ($pk) | |
{ | |
$s += " --productKey $pk" | |
$parameters.Add('RegisterProduct', "$rpp $pk 08860") | |
} | |
return $s | |
} | |
$vendor = "microsoft" | |
$product = "visualstudio" | |
$packageName = $env:chocolateyPackageName | |
$packageParameters = Parse-Parameters $env:chocolateyPackageParameters | |
$silentArgs = Generate-Install-Arguments-String $packageParameters | |
$uncPath = "\\SERVER\tools\microsoft\visualstudio\2017\mu_visual_studio_enterprise_2017_x86_x64_10049783" | |
$uncUser = "DOMAIN\user" | |
$uncPassword = "password" | |
$driveLetter = dir function:[d-z]: -n | ?{ !(test-path $_) } | random | |
NET USE $driveLetter /D 2>null | |
NET USE $driveLetter $uncPath /u:$uncUser $uncPassword | |
$packageArgs = @{ | |
packageName = $packageName | |
fileType = 'exe' | |
file = "$driveLetter\mu_visual_studio_enterprise_2017_x86_x64_10049783.exe" | |
silentArgs = $silentArgs | |
validExitCodes= @(0, 3010) | |
} | |
Write-Debug "Arguments used for $packageName`: $silentArgs" | |
Install-ChocolateyInstallPackage @packageArgs | |
NET USE $driveLetter /D 2>null | |
$rp = $packageParameters['RegisterProduct'] | |
if ($rp) | |
{ | |
Write-Debug "Register product using command line ($rp)" | |
Invoke-Expression $rp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment