From 02d1e71032afe3e19c6c98ab4d7e984b5216abd5 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 8 Jun 2022 16:48:19 +0200 Subject: [PATCH] Fixes errors on encapsulated PowerShell calls --- doc/100-General/10-Changelog.md | 1 + lib/core/framework/Install-IcingaFrameworkComponent.psm1 | 2 +- lib/core/framework/Install-IcingaFrameworkUpdate.psm1 | 2 +- lib/core/framework/Restart-IcingaService.psm1 | 2 ++ lib/core/framework/Start-IcingaService.psm1 | 2 ++ lib/core/framework/Stop-IcingaService.psm1 | 2 ++ lib/core/icingaagent/installer/Install-IcingaAgent.psm1 | 2 ++ lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 | 2 ++ lib/core/repository/Install-IcingaComponent.psm1 | 4 ++++ 9 files changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 247ab1f..debeeea 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -14,6 +14,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ### Bugfixes * [#529](https://github.com/Icinga/icinga-powershell-framework/pull/529) Fixes package manifest reader for Icinga for Windows components on Windows 2012 R2 and older +* [#523](https://github.com/Icinga/icinga-powershell-framework/pull/523) Fixes errors on encapsulated PowerShell calls for missing Cmdlets `Write-IcingaConsoleError` and `Optimize-IcingaForWindowsMemory` ### Enhancements diff --git a/lib/core/framework/Install-IcingaFrameworkComponent.psm1 b/lib/core/framework/Install-IcingaFrameworkComponent.psm1 index 200ca9e..da3dbf7 100644 --- a/lib/core/framework/Install-IcingaFrameworkComponent.psm1 +++ b/lib/core/framework/Install-IcingaFrameworkComponent.psm1 @@ -112,7 +112,7 @@ function Install-IcingaFrameworkComponent() if ([string]::IsNullOrEmpty((Get-IcingaJEAContext)) -eq $FALSE) { Write-IcingaConsoleNotice 'Updating Icinga JEA profile'; - & powershell.exe -Command { Use-Icinga; Install-IcingaJEAProfile; } | Out-Null; + & powershell.exe -Command { Use-Icinga -Minimal; Install-IcingaJEAProfile; } | Out-Null; } # Unload the module if it was loaded before diff --git a/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 b/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 index 83eed6e..6f0afb1 100644 --- a/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 +++ b/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 @@ -109,7 +109,7 @@ function Install-IcingaFrameworkUpdate() if ([string]::IsNullOrEmpty((Get-IcingaJEAContext)) -eq $FALSE) { Remove-IcingaFrameworkDependencyFile; Write-IcingaConsoleNotice 'Updating Icinga JEA profile'; - & powershell.exe -Command { Use-Icinga; Install-IcingaJEAProfile; } | Out-Null; + & powershell.exe -Command { Use-Icinga -Minimal; Install-IcingaJEAProfile; } | Out-Null; } Write-IcingaConsoleNotice 'Framework update has been completed. Please start a new PowerShell instance now to complete the update'; diff --git a/lib/core/framework/Restart-IcingaService.psm1 b/lib/core/framework/Restart-IcingaService.psm1 index c414a49..ff89a73 100644 --- a/lib/core/framework/Restart-IcingaService.psm1 +++ b/lib/core/framework/Restart-IcingaService.psm1 @@ -28,6 +28,8 @@ function Restart-IcingaService() Write-IcingaConsoleNotice ([string]::Format('Restarting service "{0}"', $Service)); & powershell.exe -Command { + Use-Icinga -Minimal; + $Service = $args[0]; try { Restart-Service "$Service" -ErrorAction Stop; diff --git a/lib/core/framework/Start-IcingaService.psm1 b/lib/core/framework/Start-IcingaService.psm1 index cd11a2f..fd24087 100644 --- a/lib/core/framework/Start-IcingaService.psm1 +++ b/lib/core/framework/Start-IcingaService.psm1 @@ -28,6 +28,8 @@ function Start-IcingaService() Write-IcingaConsoleNotice -Message 'Starting service "{0}"' -Objects $Service; & powershell.exe -Command { + Use-Icinga -Minimal; + $Service = $args[0]; try { Start-Service "$Service" -ErrorAction Stop; diff --git a/lib/core/framework/Stop-IcingaService.psm1 b/lib/core/framework/Stop-IcingaService.psm1 index 8da25db..4d56962 100644 --- a/lib/core/framework/Stop-IcingaService.psm1 +++ b/lib/core/framework/Stop-IcingaService.psm1 @@ -28,6 +28,8 @@ function Stop-IcingaService() Write-IcingaConsoleNotice -Message 'Stopping service "{0}"' -Objects $Service; & powershell.exe -Command { + Use-Icinga -Minimal; + $Service = $args[0]; try { Stop-Service "$Service" -ErrorAction Stop; diff --git a/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 b/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 index 5cf3483..0a742ea 100644 --- a/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 +++ b/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 @@ -74,6 +74,8 @@ function Install-IcingaAgent() } $InstallProcess = & powershell.exe -Command { + Use-Icinga -Minimal; + $IcingaInstaller = $args[0]; $InstallTarget = $args[1]; $InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller.InstallerPath, $InstallTarget)) -FlushNewLines; diff --git a/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 b/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 index f258ff7..f5bd7a2 100644 --- a/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 +++ b/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 @@ -23,6 +23,8 @@ function Uninstall-IcingaAgent() Stop-IcingaService -Service 'icinga2'; $Uninstaller = & powershell.exe -Command { + Use-Icinga -Minimal; + $IcingaData = $args[0]; $Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine; diff --git a/lib/core/repository/Install-IcingaComponent.psm1 b/lib/core/repository/Install-IcingaComponent.psm1 index d153ef4..52fd6c4 100644 --- a/lib/core/repository/Install-IcingaComponent.psm1 +++ b/lib/core/repository/Install-IcingaComponent.psm1 @@ -349,6 +349,8 @@ function Install-IcingaComponent() } $MSIData = & powershell.exe -Command { + Use-Icinga -Minimal; + $DownloadDestination = $args[0]; return (Read-IcingaMSIMetadata -File $DownloadDestination); } -Args $DownloadDestination; @@ -369,6 +371,8 @@ function Install-IcingaComponent() } $InstallProcess = & powershell.exe -Command { + Use-Icinga -Minimal; + $DownloadDestination = $args[0]; $InstallTarget = $args[1]; $InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $DownloadDestination, $InstallTarget)) -FlushNewLines;