Skip to content

Instantly share code, notes, and snippets.

@lennybacon
Last active January 19, 2021 17:51
Show Gist options
  • Save lennybacon/eb99d3831002b90c1d2300c7a3f6f054 to your computer and use it in GitHub Desktop.
Save lennybacon/eb99d3831002b90c1d2300c7a3f6f054 to your computer and use it in GitHub Desktop.
Headless update for Visual Studio
Write-Host "Update Visual Studio Installer" -ForegroundColor Cyan
# [Microsoft Developer community](https://developercommunity.visualstudio.com/content/problem/307261/unattend-self-update-of-vs-installer.html)
$vsCommunityDownloadUrl = "https://download.visualstudio.microsoft.com/download/pr/8a973d5d-2ccb-428c-8204-290a15d30e2c/be8c694b12879a8f47f34369d55d453c/vs_community.exe";
$vsSetupDirectory = "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Setup"
$vsCommunitySetupPath = "$vsSetupDirectory\vs_community.exe";
if((Test-Path -Path $vsSetupDirectory) -eq $false){
$r = md $vsSetupDirectory
}
if((Test-Path -Path $vsCommunitySetupPath) -eq $false){
Write-Host "Downloading VS Setup from $vsCommunityDownloadUrl..." -ForegroundColor Gray
(New-Object System.Net.WebClient).DownloadFile($vsCommunityDownloadUrl, $vsCommunitySetupPath);
}
Write-Host "Starting the VS setup to update the VS Installer" -ForegroundColor Gray
$installerUpdateProcess = Start-Process `
-FilePath $vsCommunitySetupPath `
-Wait `
-PassThru `
-ArgumentList @(
"--update",
"--quiet",
"--wait"
);
$installerUpdateProcess.WaitForExit();
Write-Host "$([IO.Path]::GetFileName($vsCommunitySetupPath)) exited with code: $($installerUpdateProcess.ExitCode)" -ForegroundColor Gray
Write-Host "Update Visual Studio" -ForegroundColor Cyan
# [Microsoft Docs](https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio)
$vsUpdateProcess= Start-Process `
-FilePath "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" `
-Wait `
-PassThru `
-ArgumentList @(
"update",
"--installPath `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community`"",
"--norestart",
"--quiet",
"--force"
);
$vsUpdateProcess.WaitForExit();
Write-Host "vs_installer.exe exited with code: $($vsUpdateProcess.ExitCode)" -ForegroundColor Gray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment