Created
June 21, 2021 13:07
-
-
Save asmichi/2ae9744254d82d09c135eaacb6aa977c to your computer and use it in GitHub Desktop.
Update all Visual Studio instances
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
# すべての Visual Studio インスタンスを更新する。管理者権限で実行する。 | |
#Requires -Version 7.0 | |
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" | |
$vs_installer = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" | |
$instances = & $vswhere -prerelease -format json -sort | ConvertFrom-Json | |
# 古いバージョンから更新する | |
[array]::Reverse($instances) | |
$rebootRequired = $false | |
$failed = $false | |
foreach ($instance in $instances) { | |
Write-Host | |
Write-Host "******************************" | |
Write-Host "*** Updating $($instance.installationName)" | |
Write-Host | |
# GUI を表示したい場合は、 --quiet ではなく --passive にする | |
$updateArgs = "update --quiet --norestart --installPath `"$($instance.installationPath)`"" | |
$p = Start-Process -FilePath $vs_installer -ArgumentList $updateArgs -Wait -PassThru | |
# https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2019#error-codes | |
switch ($p.ExitCode) { | |
0 { } | |
3010 { $rebootRequired = $true } | |
Default { $failed = $true } | |
} | |
if ($failed) { | |
break | |
} | |
} | |
Write-Host | |
if ($failed) { | |
Write-Host "******************************" | |
Write-Host "*** ERROR ***" | |
Write-Host "******************************" | |
exit 1 | |
} | |
elseif ($rebootRequired) { | |
Write-Host "******************************" | |
Write-Host "*** REBOOT REQUIRED ***" | |
Write-Host "******************************" | |
exit 3010 | |
} | |
else { | |
Write-Host "SUCCESS!" | |
exit 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved to https://github.com/asmichi/playground/blob/master/src/Tools/UpdateAllVisualStudioInstances.ps1