From 28efe625482e5670369ca9640cee99eba0a3531a Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 11 May 2022 15:02:29 +0200 Subject: [PATCH] Fixes missing loading for IfW modules --- doc/100-General/10-Changelog.md | 8 ++++++++ icinga-powershell-framework.psm1 | 30 +++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 4d5a1c9..105bcbd 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -7,6 +7,14 @@ documentation before upgrading to a new release. Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-framework/milestones?state=closed). +## 1.9.1 (2022-05-13) + +### Bugfixes + +[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/24?closed=1) + +* [#519](https://github.com/Icinga/icinga-powershell-framework/pull/519) Fixes missing loading of Icinga for Windows modules, which is required to ensure an Icinga for Windows environment is providing all commands and variables to a session, allowing other modules to access these information + ## 1.9.0 (2022-05-03) [Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/20?closed=1) diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index 3694f6a..4b588a0 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -28,11 +28,8 @@ function Use-Icinga() $Global:Icinga.Protected.Minimal = $TRUE; } - # Ensure we autoload the Icinga Plugin collection, provided by the external - # module 'icinga-powershell-plugins' - if (Get-Command 'Use-IcingaPlugins' -ErrorAction SilentlyContinue) { - Use-IcingaPlugins; - } + # Ensure we autoload Icinga for Windows modules into this session + Import-IcingaForWindowsModulesInSession; if ($Daemon) { $Global:Icinga.Protected.RunAsDaemon = $TRUE; @@ -64,6 +61,29 @@ function Use-Icinga() } } +function Import-IcingaForWindowsModulesInSession() +{ + $CommandList = Get-Command 'Import-IcingaPowerShellComponent*'; + + foreach ($entry in $CommandList) { + $ModuleName = $entry.Module.Name; + $ModulePath = $entry.Module.Path; + $RootPath = $ModulePath.Substring(0, $ModulePath.IndexOf($ModuleName)); + $Command = $entry.Name; + + if ($RootPath.ToLower() -ne (Get-IcingaForWindowsRootPath).ToLower()) { + continue; + } + + if ([string]::IsNullOrEmpty($Command) -Or (Test-IcingaFunction $Command) -eq $FALSE) { + continue; + } + + # Execute the command if the module is located at the same location as our Framework + & $Command | Out-Null; + } +} + function Get-IcingaFrameworkCodeCacheFile() { return (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework_cache.psm1');