Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/100-General/10-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Enhancements

* [#544](https://github.com/Icinga/icinga-powershell-framework/issues/544) Adds support to configure the Icinga Director JSON string for registering hosts via self-service API
* [#573](https://github.com/Icinga/icinga-powershell-framework/issues/573) Adds support to run command `icinga` with new argument `-NoNewInstance`, to use `-RebuildCache` as example to update the current PowerShell instance with all applied changes
* [#619](https://github.com/Icinga/icinga-powershell-framework/pull/619) Adds feature to securely read enum provider values with new function `Get-IcingaProviderEnumData`
* [#623](https://github.com/Icinga/icinga-powershell-framework/issues/623) Adds support to provide the Icinga service user written as `user@domain`
* [#633](https://github.com/Icinga/icinga-powershell-framework/pull/633) Adds support for Icinga 2.14.0 native Icinga for Windows API communication
Expand Down
33 changes: 33 additions & 0 deletions icinga-powershell-framework.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ function Import-IcingaForWindowsModulesInSession()
}
}

function Import-IcingaForWindowsModules()
{
[array]$IcingaForWindowsModules = Get-ChildItem -Path (Get-IcingaForWindowsRootPath);

foreach ($module in $IcingaForWindowsModules) {
if ($module.Name -Like 'icinga-powershell-*') {
try {
Import-Module $module.Name -Force -ErrorAction Stop;
Import-Module $module.Name -Force -Global -ErrorAction Stop;
} catch {
Write-Host ([string]::Format('Failed to import Icinga for Windows module "{0}": {1}', $module.Name, $_.Exception.Message));
}
}
}

Import-Module 'icinga-powershell-framework' -Force;
Import-Module 'icinga-powershell-framework' -Force -Global;
}

function Get-IcingaFrameworkCodeCacheFile()
{
return (Join-Path -Path (Get-IcingaCacheDir) -ChildPath 'framework_cache.psm1');
Expand Down Expand Up @@ -249,9 +268,15 @@ function Invoke-IcingaCommand()
[switch]$NoSSLValidation = $FALSE,
[switch]$RebuildCache = $FALSE,
[switch]$DeveloperMode = $FALSE,
[switch]$NoNewInstance = $FALSE,
[array]$ArgumentList = @()
);

If ($DeveloperMode -And $NoNewInstance) {
Write-Host 'DeveloperMode is not supported while using NoNewInstance argument.' -ForegroundColor red;
return;
}

Import-LocalizedData `
-BaseDirectory (Get-IcingaFrameworkRootPath) `
-FileName 'icinga-powershell-framework.psd1' `
Expand Down Expand Up @@ -285,6 +310,14 @@ function Invoke-IcingaCommand()
Write-IcingaFrameworkCodeCache -DeveloperMode:$DeveloperMode;
}

# Try to re-import everything within the same instance
if ($NoNewInstance) {
Import-IcingaForWindowsModules;
Use-Icinga;

return;
}

if ($null -ne $psISE) {
Use-Icinga;
Write-IcingaConsoleError -Message 'Icinga for Windows was loaded, but the Icinga Management Console is not available within the PowerShell ISE context. Please start a regular PowerShell to use it.';
Expand Down