Skip to content

Instantly share code, notes, and snippets.

@yujinlin0224
Last active February 28, 2023 11:39
Show Gist options
  • Save yujinlin0224/a1576b5a3bd4d0a2e2f8843be0e0c1d9 to your computer and use it in GitHub Desktop.
Save yujinlin0224/a1576b5a3bd4d0a2e2f8843be0e0c1d9 to your computer and use it in GitHub Desktop.
[Deprecated, use winget instead] Install all redistributable packages for Windows, including Microsoft Visual C++ 2005-2022 Redistributable Packages and DirectX End-User Runtime.
$tempPath = [System.IO.Path]::GetTempPath()
$vcredistUrlTable = [ordered]@{
'2005'=[ordered]@{
'x86'='https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.EXE'
'x64'='https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.EXE'
}
'2008'=[ordered]@{
'x86'='https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x86.exe'
'x64'='https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x64.exe'
}
'2010'=[ordered]@{
'x86'='https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe'
'x64'='https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe'
}
'2012'=[ordered]@{
'x86'='https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe'
'x64'='https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe'
}
'2013'=[ordered]@{
'x86'='https://aka.ms/highdpimfc2013x86enu'
'x64'='https://aka.ms/highdpimfc2013x64enu'
}
'2015-2022'=[ordered]@{
'x86'='https://aka.ms/vs/17/release/vc_redist.x86.exe'
'x64'='https://aka.ms/vs/17/release/vc_redist.x64.exe'
}
}
$vcredistArgsTable = [ordered]@{
'2005'=@('/Q')
'2008'=@('/Q')
'2010'=@('/passive', '/norestart')
'2012'=@('/passive', '/norestart')
'2013'=@('/passive', '/norestart')
'2015-2022'=@('/passive', '/norestart')
}
foreach ($vcredistVer in $vcredistUrlTable.Keys) {
foreach ($vcredistArch in $vcredistUrlTable[$vcredistVer].Keys) {
$vcredistUrl = $vcredistUrlTable[$vcredistVer][$vcredistArch]
$vcredistFilePath = [System.IO.Path]::Combine($tempPath, "vcredist$($vcredistVer)_$($vcredistArch).exe")
$vcredistArgs = $vcredistArgsTable[$vcredistVer]
Invoke-WebRequest $vcredistUrl -OutFile $vcredistFilePath
Start-Process $vcredistFilePath $vcredistArgs -Wait
Remove-Item $vcredistFilePath
}
}
$dxredistUrl = 'https://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe'
$dxredistFilePath = [System.IO.Path]::Combine($tempPath, [System.IO.Path]::GetFileName($dxredistUrl))
$dxredistDirPath = [System.IO.Path]::Combine($tempPath, [System.IO.Path]::GetFileNameWithoutExtension($dxredistUrl))
Invoke-WebRequest $dxredistUrl -OutFile $dxredistFilePath
Start-Process $dxredistFilePath @('/Q', "/T:$dxredistDirPath") -Wait
Start-Process "$([System.IO.Path]::Combine($dxredistDirPath, 'DXSETUP.exe'))" @('/silent') -Wait
Remove-Item $dxredistFilePath
Remove-Item $dxredistDirPath -Recurse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment