Multi-line outputs in CheckMK with a variable

Hello everyone,

I am working on a small script for CheckMK. CheckMK requires a special syntax as described in section 2.1. Link

In my script I have a variable that may contain several objects. I would like to display these objects one below the other. According to CheckMK, this is possible with “\n”, as described in section 3.6. Link

However, I don’t know how to implement this in PowerShell.
Could someone help me here?

if ($duplicates) {
Write-Host “1 “SericeName:” - $duplicates”
} else {
Write-Host “0 “SericeName:” - No duplicate email addresses found.”
}

If I am not mistaken, “\n” is the character for a new line. You can create a new line in Powershell like this example.

"Test1 `nTest2"

Yes thats right, but i dont know how to implement this in my code/variable.

I Think ist should looks something like

Write-Host “1 “SericeName:” - $duplicates[0]\n$duplicates[1]\n$duplicates[2]"
But i am not sure how to implement a loop of the length of the array in a Write-Host.

Does the amount of duplicates you have in your variable $duplicates vary? You could use the -join operator to join all duplicates with a “`n”

Something like this:

$Duplicates =
1..4 | 
    ForEach-Object {
        "Dublette_$_"
    }
$Duplicates -join "`n"

Yes, the number can vary. Ideally it should be 0, but it can also be 10 objects in the variable.

OK. Have you tried my suggestion?