Adds support to check for required .NET Framework 4.6.0 version

Fixes #76
This commit is contained in:
Lord Hepipud 2020-07-29 14:28:28 +02:00
parent 1a52157ec2
commit 15e5e1efef
3 changed files with 56 additions and 1 deletions

View file

@ -17,7 +17,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Enhancements ### Enhancements
* Adds new Cmdlet `Show-IcingaPerformanceCounterInstances` to display all avaiable instances for Performance Counters * Adds new Cmdlet `Show-IcingaPerformanceCounterInstances` to display all available instances for Performance Counters
* [#76](https://github.com/Icinga/icinga-powershell-framework/issues/76) Adds support to test for required .NET Framework Version 4.6.0 or above before trying to install the Icinga Agent
### Bugfixes ### Bugfixes

View file

@ -544,6 +544,11 @@ function Start-IcingaAgentInstallWizard()
} }
if ($RunInstaller) { if ($RunInstaller) {
if ((Test-IcingaAgentNETFrameworkDependency) -eq $FALSE) {
Write-IcingaConsoleError -Message 'You cannot install the Icinga Agent on this system as the required .NET Framework version is not installed. Please install .NET Framework 4.6.0 or later and use the above provided install arguments to try again.'
return;
}
if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges -InstallDir $InstallDir) -Or $Reconfigure) { if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges -InstallDir $InstallDir) -Or $Reconfigure) {
Reset-IcingaAgentConfigFile; Reset-IcingaAgentConfigFile;
Move-IcingaAgentDefaultConfig; Move-IcingaAgentDefaultConfig;

View file

@ -0,0 +1,49 @@
<#
.SYNOPSIS
Test if .NET Framework 4.6.0 or above is installed which is required by
the Icinga Agent. Returns either true or false - depending on if the
.NET Framework 4.6.0 or above is installed or not
.DESCRIPTION
Test if .NET Framework 4.6.0 or above is installed which is required by
the Icinga Agent. Returns either true or false - depending on if the
.NET Framework 4.6.0 or above is installed or not
.FUNCTIONALITY
Test if .NET Framework 4.6.0 or above is installed
.EXAMPLE
PS>Test-IcingaAgentNETFrameworkDependency;
.OUTPUTS
System.Boolean
.LINK
https://github.com/Icinga/icinga-powershell-framework
https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
#>
function Test-IcingaAgentNETFrameworkDependency()
{
$RegistryContent = Get-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -ErrorAction SilentlyContinue;
# We require at least .NET Framework 4.6.0 to be installed on the system
# Version on Windows 10: 393295
# Version on any other system: 393297
# We do only require to check for the Windows 10 version, as the other Windows verions
# do not cause an issue there then because of how the next versions are iterated
if ($null -eq $RegistryContent -Or $RegistryContent.Release -lt 393295) {
if ($null -eq $RegistryContent) {
$RegistryContent = @{
'Version' = 'Unknown'
};
}
Write-IcingaConsoleError `
-Message 'To install the Icinga Agent you will require .NET Framework 4.6.0 or later to be installed on the system. Current installed version: {0}' `
-Objects $RegistryContent.Version;
return $FALSE;
}
Write-IcingaConsoleNotice `
-Message 'Found installed .NET Framework version {0}' `
-Objects $RegistryContent.Version;
return $TRUE;
}