diff --git a/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerEngine.ps1 b/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerEngine.ps1 index 1016f21c9a..b76aebab6f 100644 --- a/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerEngine.ps1 +++ b/Diagnostics/HealthChecker/Analyzer/Invoke-AnalyzerEngine.ps1 @@ -579,32 +579,18 @@ Function Invoke-AnalyzerEngine { $displayValue2013 = "Unknown" if ($null -ne $osInformation.VcRedistributable) { - Write-VerboseOutput("VCRedist2012 Testing value: {0}" -f [HealthChecker.VCRedistVersion]::VCRedist2012.value__) - Write-VerboseOutput("VCRedist2013 Testing value: {0}" -f [HealthChecker.VCRedistVersion]::VCRedist2013.value__) - foreach ($detectedVisualRedistVersion in $osInformation.VcRedistributable) { - Write-VerboseOutput("Testing {0} version id '{1}'" -f $detectedVisualRedistVersion.DisplayName, $detectedVisualRedistVersion.VersionIdentifier) - - if ($detectedVisualRedistVersion.DisplayName -like "Microsoft Visual C++ 2012*") { - $vcRedist2012Detected = $true - if ($detectedVisualRedistVersion.VersionIdentifier -eq [HealthChecker.VCRedistVersion]::VCRedist2012) { - $displayWriteType2012 = "Green" - $displayValue2012 = "{0} Version is current" -f $detectedVisualRedistVersion.DisplayVersion - } - } elseif ($detectedVisualRedistVersion.DisplayName -like "Microsoft Visual C++ 2013*") { - $vcRedist2013Detected = $true - if ($detectedVisualRedistVersion.VersionIdentifier -eq [HealthChecker.VCRedistVersion]::VCRedist2013) { - $displayWriteType2013 = "Green" - $displayValue2013 = "{0} Version is current" -f $detectedVisualRedistVersion.DisplayVersion - } - } - } - - if (($vcRedist2012Detected -eq $true) -and ($displayWriteType2012 -ne "Green")) { + if (Test-VisualCRedistributableUpToDate -Year 2012 -Installed $osInformation.VcRedistributable) { + $displayWriteType2012 = "Green" + $displayValue2012 = "$((Get-VisualCRedistributableInfo 2012).VersionNumber) Version is current" + } elseif (Test-VisualCRedistributableInstalled -Year 2012 -Installed $osInformation.VcRedistributable) { $displayValue2012 = "Redistributable is outdated" } - if (($vcRedist2013Detected -eq $true) -and ($displayWriteType2013 -ne "Green")) { + if (Test-VisualCRedistributableUpToDate -Year 2013 -Installed $osInformation.VcRedistributable) { + $displayWriteType2013 = "Green" + $displayValue2013 = "$((Get-VisualCRedistributableInfo 2013).VersionNumber) Version is current" + } elseif (Test-VisualCRedistributableInstalled -Year 2013 -Installed $osInformation.VcRedistributable) { $displayValue2013 = "Redistributable is outdated" } } diff --git a/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 b/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 index 7a6e494f91..cdec219a2d 100644 --- a/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 +++ b/Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-OperatingSystemInformation.ps1 @@ -71,7 +71,7 @@ Function Get-OperatingSystemInformation { -ScriptBlockDescription "Getting Current Time Zone" ` -CatchActionFunction ${Function:Invoke-CatchActions} $osInformation.TLSSettings = Get-AllTlsSettingsFromRegistry -MachineName $Script:Server -CatchActionFunction ${Function:Invoke-CatchActions} - $osInformation.VcRedistributable = Get-VisualCRedistributableVersion -ComputerName $Script:Server -CatchActionFunction ${Function:Invoke-CatchActions} + $osInformation.VcRedistributable = Get-VisualCRedistributableInstalledVersion -ComputerName $Script:Server -CatchActionFunction ${Function:Invoke-CatchActions} $osInformation.CredentialGuardEnabled = Get-CredentialGuardEnabled $osInformation.RegistryValues.CurrentVersionUbr = Invoke-RegistryGetValue ` -MachineName $Script:Server ` diff --git a/Diagnostics/HealthChecker/HealthChecker.ps1 b/Diagnostics/HealthChecker/HealthChecker.ps1 index 4c9d68eae7..307923e851 100644 --- a/Diagnostics/HealthChecker/HealthChecker.ps1 +++ b/Diagnostics/HealthChecker/HealthChecker.ps1 @@ -185,7 +185,7 @@ if ($PSBoundParameters["Verbose"]) { . .\DataCollection\ServerInformation\Get-OperatingSystemInformation.ps1 . .\DataCollection\ServerInformation\Get-PageFileInformation.ps1 . .\DataCollection\ServerInformation\Get-ServerRole.ps1 -. $PSScriptRoot\..\..\Shared\Get-VisualCRedistributableVersion.ps1 +. $PSScriptRoot\..\..\Shared\VisualCRedistributableVersionFunctions.ps1 . .\Analyzer\Add-AnalyzedResultInformation.ps1 . .\Analyzer\Get-DisplayResultsGroupingKey.ps1 . .\Analyzer\Invoke-AnalyzerEngine.ps1 diff --git a/Diagnostics/HealthChecker/Helpers/Class.ps1 b/Diagnostics/HealthChecker/Helpers/Class.ps1 index 2e04aa2dde..a239ee44da 100644 --- a/Diagnostics/HealthChecker/Helpers/Class.ps1 +++ b/Diagnostics/HealthChecker/Helpers/Class.ps1 @@ -242,15 +242,6 @@ try { public string Seconds; } - //enum for the dword values of the latest supported VC++ redistributable releases - //https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads - public enum VCRedistVersion - { - Unknown = 0, - VCRedist2012 = 184610406, - VCRedist2013 = 201367256 - } - public class OSNetFrameworkInformation { public NetMajorVersion NetMajorVersion; //NetMajorVersion value diff --git a/Setup/SetupAssist/Checks/Test-PrerequisiteInstalled.ps1 b/Setup/SetupAssist/Checks/Test-PrerequisiteInstalled.ps1 index ce0e804fb7..e93dbaf1aa 100644 --- a/Setup/SetupAssist/Checks/Test-PrerequisiteInstalled.ps1 +++ b/Setup/SetupAssist/Checks/Test-PrerequisiteInstalled.ps1 @@ -4,10 +4,7 @@ Function Test-PrerequisiteInstalled { [CmdletBinding()] param() - begin { - $2012VersionFound = $false - $2013VersionFound = $false - } + process { $netVersion = Get-NETFrameworkVersion @@ -15,23 +12,14 @@ Function Test-PrerequisiteInstalled { "Download .NET 4.8 and install: https://dotnet.microsoft.com/download/dotnet-framework/net48" | Receive-Output } - $vcRedistributable = Get-VisualCRedistributableVersion - - foreach ($detectedVc in $vcRedistributable) { - - if ($detectedVc.VersionIdentifier -eq 201347597) { - $2013VersionFound = $true - } elseif ($detectedVc.VersionIdentifier -eq 184600103) { - $2012VersionFound = $true - } - } + $installed = Get-VisualCRedistributableInstalledVersion - if (-not $2012VersionFound) { - "Download Visual C++ 2012 Redistributable Package and install: https://www.microsoft.com/en-us/download/details.aspx?id=30679" | Receive-Output + if (-not (Test-VisualCRedistributableUpToDate -Year 2012 -Installed $installed)) { + "Download Visual C++ 2012 Redistributable Package and install: $((Get-VisualCRedistributableInfo 2012).DownloadUrl)" | Receive-Output } - if (-not $2013VersionFound) { - "Download Visual C++ 2013 Redistributable Package and install: https://support.microsoft.com/en-us/topic/update-for-visual-c-2013-redistributable-package-d8ccd6a5-4e26-c290-517b-8da6cfdf4f10" | Receive-Output + if (-not (Test-VisualCRedistributableUpToDate -Year 2013 -Installed $installed)) { + "Download Visual C++ 2013 Redistributable Package and install: $((Get-VisualCRedistributableInfo 2013).DownloadUrl)" | Receive-Output } } } diff --git a/Setup/SetupAssist/Checks/Test-ValidHomeMdb.ps1 b/Setup/SetupAssist/Checks/Test-ValidHomeMdb.ps1 index 43e5d2b9d7..bbfb0ac382 100644 --- a/Setup/SetupAssist/Checks/Test-ValidHomeMdb.ps1 +++ b/Setup/SetupAssist/Checks/Test-ValidHomeMdb.ps1 @@ -3,7 +3,10 @@ Function Test-ValidHomeMDB { $filePath = "$PSScriptRoot\validHomeMdb.txt" - ldifde -t 3268 -r "(&(objectClass=user)(mailnickname=*)(!(msExchRemoteRecipientType=*))(!(targetAddress=*))(msExchHideFromAddressLists=TRUE)(!(cn=HealthMailbox*)))" -l "distinguishedName,homeMDB" -f $filePath | Out-Null + $rootDSE = [ADSI]("LDAP://RootDSE") + ldifde -t 3268 -r "(&(objectClass=user)(mailnickname=*)(!(msExchRemoteRecipientType=*))(!(targetAddress=*))(msExchHideFromAddressLists=TRUE)(!(cn=HealthMailbox*)))" ` + -l "distinguishedName,homeMDB" -f $filePath -d $rootDSE.rootDomainNamingContext | Out-Null + $ldifeObject = @(Get-Content $filePath | ConvertFrom-Ldif) if ($ldifeObject.Count -gt 0) { @@ -43,6 +46,6 @@ Function Test-ValidHomeMDB { "All Critical Mailboxes have valid HomeMDB values" | Receive-Output } } else { - throw "Unexpected LDIF data." + Write-Error "Unexpected LDIF data in Test-ValidHomeMdb." } } diff --git a/Setup/SetupAssist/SetupAssist.ps1 b/Setup/SetupAssist/SetupAssist.ps1 index 557a1b1cb6..70d317ef57 100644 --- a/Setup/SetupAssist/SetupAssist.ps1 +++ b/Setup/SetupAssist/SetupAssist.ps1 @@ -33,7 +33,7 @@ param( #REPO Shared . $PSScriptRoot\..\..\Shared\Test-ScriptVersion.ps1 . $PSScriptRoot\..\..\Shared\Get-NETFrameworkVersion.ps1 -. $PSScriptRoot\..\..\Shared\Get-VisualCRedistributableVersion.ps1 +. $PSScriptRoot\..\..\Shared\VisualCRedistributableVersionFunctions.ps1 #REPO Shared Dependencies . $PSScriptRoot\..\..\Shared\Get-RemoteRegistrySubKey.ps1 diff --git a/Shared/Get-VisualCRedistributableVersion.ps1 b/Shared/Get-VisualCRedistributableVersion.ps1 deleted file mode 100644 index 4da421ec87..0000000000 --- a/Shared/Get-VisualCRedistributableVersion.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -Function Get-VisualCRedistributableVersion { - [CmdletBinding()] - param( - [string]$ComputerName = $env:COMPUTERNAME, - [scriptblock]$CatchActionFunction - ) - begin { - Write-Verbose "Calling: Get-VisualCRedistributableVersion" - $softwareList = New-Object 'System.Collections.Generic.List[object]' - } - process { - $installedSoftware = Invoke-ScriptBlockHandler -ComputerName $ComputerName ` - -ScriptBlock { Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* } ` - -ScriptBlockDescription "Querying for software" ` - -CatchActionFunction $CatchActionFunction - - foreach ($software in $installedSoftware) { - - if ($software.DisplayName -like "Microsoft Visual C++ *") { - Write-Verbose "Microsoft Visual C++ Found: $($software.DisplayName)" - $softwareList.Add([PSCustomObject]@{ - DisplayName = $software.DisplayName - DisplayVersion = $software.DisplayVersion - InstallDate = $software.InstallDate - VersionIdentifier = $software.Version - }) - } - } - } - end { - Write-Verbose "Exiting: Get-VisualCRedistributableVersion" - return $softwareList - } -} diff --git a/Shared/VisualCRedistributableVersionFunctions.ps1 b/Shared/VisualCRedistributableVersionFunctions.ps1 new file mode 100644 index 0000000000..223a7ec965 --- /dev/null +++ b/Shared/VisualCRedistributableVersionFunctions.ps1 @@ -0,0 +1,101 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +. $PSScriptRoot\Invoke-ScriptBlockHandler.ps1 + +Function Get-VisualCRedistributableInstalledVersion { + [CmdletBinding()] + param( + [string]$ComputerName = $env:COMPUTERNAME, + [scriptblock]$CatchActionFunction + ) + begin { + Write-Verbose "Calling: $($MyInvocation.MyCommand)" + $softwareList = New-Object 'System.Collections.Generic.List[object]' + } + process { + $installedSoftware = Invoke-ScriptBlockHandler -ComputerName $ComputerName ` + -ScriptBlock { Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* } ` + -ScriptBlockDescription "Querying for software" ` + -CatchActionFunction $CatchActionFunction + + foreach ($software in $installedSoftware) { + + if ($software.DisplayName -like "Microsoft Visual C++ *") { + Write-Verbose "Microsoft Visual C++ Found: $($software.DisplayName)" + $softwareList.Add([PSCustomObject]@{ + DisplayName = $software.DisplayName + DisplayVersion = $software.DisplayVersion + InstallDate = $software.InstallDate + VersionIdentifier = $software.Version + }) + } + } + } + end { + Write-Verbose "Exiting: $($MyInvocation.MyCommand)" + return $softwareList + } +} + +Function Get-VisualCRedistributableInfo { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [ValidateSet(2012, 2013)] + [int] + $Year + ) + + if ($Year -eq 2012) { + return [PSCustomObject]@{ + VersionNumber = 184610406 + DownloadUrl = "https://www.microsoft.com/en-us/download/details.aspx?id=30679" + DisplayName = "Microsoft Visual C++ 2012*" + } + } else { + return [PSCustomObject]@{ + VersionNumber = 201367256 + DownloadUrl = "https://support.microsoft.com/en-us/topic/update-for-visual-c-2013-redistributable-package-d8ccd6a5-4e26-c290-517b-8da6cfdf4f10" + DisplayName = "Microsoft Visual C++ 2013*" + } + } +} + +Function Test-VisualCRedistributableInstalled { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true, Position = 0)] + [ValidateSet(2012, 2013)] + [int] + $Year, + + [Parameter(Mandatory = $true, Position = 1)] + [object] + $Installed + ) + + $desired = Get-VisualCRedistributableInfo $Year + + return ($null -ne $Installed | Where-Object { $_.DisplayName -like $desired.DisplayName }) +} + +Function Test-VisualCRedistributableUpToDate { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true, Position = 0)] + [ValidateSet(2012, 2013)] + [int] + $Year, + + [Parameter(Mandatory = $true, Position = 1)] + [object] + $Installed + ) + + $desired = Get-VisualCRedistributableInfo $Year + + return ($null -ne ($Installed | Where-Object { + $_.DisplayName -like $desired.DisplayName -and $_.VersionIdentifier -eq $desired.VersionNumber + })) +}