Fixes non string values for file writer

This commit is contained in:
Lord Hepipud 2021-08-21 14:13:49 +02:00
parent 1241c58909
commit c7ff7f14ad

View file

@ -9,6 +9,18 @@ function Write-IcingaFileSecure()
return; 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) { if ((Test-Path $File) -eq $FALSE) {
try { try {
New-Item -ItemType File -Path $File -ErrorAction Stop | Out-Null; New-Item -ItemType File -Path $File -ErrorAction Stop | Out-Null;