diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index abec908..55968dc 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -17,7 +17,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ### 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 diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 index fba141c..c01d7e2 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 @@ -544,6 +544,11 @@ function Start-IcingaAgentInstallWizard() } 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) { Reset-IcingaAgentConfigFile; Move-IcingaAgentDefaultConfig; diff --git a/lib/core/icingaagent/tests/Test-IcingaAgentNETFrameworkDependency.psm1 b/lib/core/icingaagent/tests/Test-IcingaAgentNETFrameworkDependency.psm1 new file mode 100644 index 0000000..93254e0 --- /dev/null +++ b/lib/core/icingaagent/tests/Test-IcingaAgentNETFrameworkDependency.psm1 @@ -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; +}