From c7ff7f14ad79cd22d5aec99eb94d59e56698bd26 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Sat, 21 Aug 2021 14:13:49 +0200 Subject: [PATCH] Fixes non string values for file writer --- lib/core/tools/Write-IcingaFileSecure.psm1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/core/tools/Write-IcingaFileSecure.psm1 b/lib/core/tools/Write-IcingaFileSecure.psm1 index 56cf9b3..fdef2b2 100644 --- a/lib/core/tools/Write-IcingaFileSecure.psm1 +++ b/lib/core/tools/Write-IcingaFileSecure.psm1 @@ -9,6 +9,18 @@ function Write-IcingaFileSecure() return; } + if ($null -eq $Value) { + $Value = ''; + } elseif ($Value.GetType().Name.ToLower() -eq 'hashtable') { + $Value = ConvertTo-Json -InputObject $Value -Depth 100; + } elseif (([string]($Value.GetType().BaseType)).ToLower() -eq 'array') { + $Value = $Value | Out-String; + } elseif ($Value.GetType().Name.ToLower() -eq 'pscustomobject') { + $Value = ConvertTo-Json -InputObject $Value -Depth 100; + } else { + $Value = $Value | Out-String; + } + if ((Test-Path $File) -eq $FALSE) { try { New-Item -ItemType File -Path $File -ErrorAction Stop | Out-Null;