From 2e225e1ce5c20c70a0099b91025d75e65704bd09 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Wed, 25 Mar 2020 17:51:53 +0100 Subject: [PATCH] Adds support for generic call of wildcard functions for fetching multi data --- .../Invoke-IcingaNamespaceCmdlets.psm1 | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/core/framework/Invoke-IcingaNamespaceCmdlets.psm1 diff --git a/lib/core/framework/Invoke-IcingaNamespaceCmdlets.psm1 b/lib/core/framework/Invoke-IcingaNamespaceCmdlets.psm1 new file mode 100644 index 0000000..c4b88dd --- /dev/null +++ b/lib/core/framework/Invoke-IcingaNamespaceCmdlets.psm1 @@ -0,0 +1,30 @@ +function Invoke-IcingaNamespaceCmdlets() +{ + param ( + [string]$Command + ); + + [Hashtable]$CommandConfig = @{}; + + if ($Command.Contains('*') -eq $FALSE) { + $Command = [string]::Format('{0}*', $Command); + } + + $CommandList = Get-Command $Command; + + foreach ($Cmdlet in $CommandList) { + try { + $CmmandName = $Cmdlet.Name; + Import-Module $Cmdlet.Module.Path -WarningAction SilentlyContinue -ErrorAction Stop; + + $Content = (& $CmmandName); + Add-IcingaHashtableItem -Hashtable $CommandConfig ` + -Key $Cmdlet.Name ` + -Value $Content | Out-Null; + } catch { + # TODO: Add event log logging on exceptions + } + } + + return $CommandConfig; +}