Skip to content

Commit 8302903

Browse files
authored
Merge pull request #155 from Icinga/feature/enable_debug_output_for_Wmi_calls
Feature: Add debug output for Get-IcingaWindowsInformation calls to EventLog Adds support to write all objects collected by `Get-IcingaWindowsInformation` into the Windows EventLog in case the debug output for the Icinga PowerShell Framework is enabled.
2 parents f166949 + 3ae042b commit 8302903

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2020
* [#134](https://github.com/Icinga/icinga-powershell-framework/pull/134) Adds Cmdlet `Test-IcingaWindowsInformation` to check if a WMI class exist and if we can fetch data from it. In addition we add support for binary value comparison with the new Cmdlet `Test-IcingaBinaryOperator`
2121
* [#142](https://github.com/Icinga/icinga-powershell-framework/pull/142) **Experimental:** Adds feature to cache the Framework code into a single file to speed up the entire loading process, mitigating the impact on performance on systems with few CPU cores. You enable disables this feature by using `Enable-IcingaFrameworkCodeCache` and `Disable-IcingaFrameworkCodeCache`. Updating the cache is done with `Write-IcingaFrameworkCodeCache`
2222
* [#149](https://github.com/Icinga/icinga-powershell-framework/pull/149) Adds support to add Wmi permissions for a specific user and namespace with `Add-IcingaWmiPermissions`. In addition you can remove users from Wmi namespaces by using `Remove-IcingaWmiPermissions`
23+
* [#155](https://github.com/Icinga/icinga-powershell-framework/pull/155) Adds support to write all objects collected by `Get-IcingaWindowsInformation` into the Windows EventLog in case the debug output for the Icinga PowerShell Framework is enabled.
2324

2425
### Bugfixes
2526

lib/wmi/Get-IcingaWindowsInformation.psm1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ function Get-IcingaWindowsInformation()
5555

5656
if ($ForceWMI -eq $FALSE -And (Get-Command 'Get-CimInstance' -ErrorAction SilentlyContinue)) {
5757
try {
58-
return (Get-CimInstance @Arguments -ErrorAction Stop);
58+
$CimData = (Get-CimInstance @Arguments -ErrorAction Stop);
59+
60+
Write-IcingaDebugMessage 'Debug output for "Get-IcingaWindowsInformation::Get-CimInstance"' -Objects $ClassName, $Filter, $Namespace, ($CimData | Out-String);
61+
62+
return $CimData;
5963
} catch {
6064
$ErrorName = $_.Exception.NativeErrorCode;
6165
$ErrorMessage = $_.Exception.Message;
@@ -84,7 +88,11 @@ function Get-IcingaWindowsInformation()
8488

8589
if ((Get-Command 'Get-WmiObject' -ErrorAction SilentlyContinue)) {
8690
try {
87-
return (Get-WmiObject @Arguments -ErrorAction Stop);
91+
$WmiData = (Get-WmiObject @Arguments -ErrorAction Stop);
92+
93+
Write-IcingaDebugMessage 'Debug output for "Get-IcingaWindowsInformation::Get-WmiObject"' -Objects $ClassName, $Filter, $Namespace, ($WmiData | Out-String);
94+
95+
return $WmiData;
8896
} catch {
8997
$ErrorName = $_.CategoryInfo.Category;
9098
$ErrorMessage = $_.Exception.Message;

0 commit comments

Comments
 (0)