-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssert-VisualCRedistributableInstalled.ps1
More file actions
58 lines (50 loc) · 2.21 KB
/
Copy pathAssert-VisualCRedistributableInstalled.ps1
File metadata and controls
58 lines (50 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function Assert-VisualCRedistributableInstalled {
<#
.SYNOPSIS
Determines if a version of the Visual C++ Redistributable is installed and meets the specified minimum version.
.DESCRIPTION
This function checks whether the Visual C++ Redistributable for Visual Studio 2015 or later is installed on
the system and ensures that the installed version is greater than or equal to the specified minimum version.
If the required version is not found, a warning is displayed, suggesting where to download the latest
redistributable package.
.EXAMPLE
Assert-VisualCRedistributableInstalled -Version '14.29.30037'
Output:
```powershell
True
```
Checks if the installed Visual C++ Redistributable version is at least 14.29.30037 and returns `$true`
if the requirement is met.
#>
[CmdletBinding()]
[OutputType([bool])]
param(
# The minimum required version of the Visual C++ Redistributable.
[Parameter(Mandatory)]
[Version] $Version,
# The process architecture that determines which Redistributable runtime is required.
[Parameter()]
[ValidateSet('X64', 'X86')]
[string] $Architecture = $(if ([System.Environment]::Is64BitProcess) { 'X64' } else { 'X86' })
)
begin {
$result = $false
}
process {
if ($IsWindows) {
$key = "HKLM:\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\$Architecture"
$runtimeInfo = Get-ItemProperty -Path $key -ErrorAction SilentlyContinue
if ($runtimeInfo -and $runtimeInfo.Version -and ($runtimeInfo.Installed -ne 0)) {
$installedVersion = [Version]$runtimeInfo.Version.TrimStart('v', 'V')
$result = $installedVersion -ge $Version
}
}
if (-not $result) {
Write-Warning "The Visual C++ Redistributable for Visual Studio 2015 or later ($Architecture) is required."
Write-Warning 'Download and install the appropriate version from:'
Write-Warning ' - https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads'
}
$result
}
end {}
}