Formatting message output from a Powershell monitor

Hello,

I will start by saying I am very new to Solarwinds.

I am trying to create a PS monitor that will monitor for user accounts that have not been logged into for more than 30 days. I have the script (see below) that works in Powershell. I managed to get the statistics counter so I can set thresholds for alerts. The last thing I need is a readable printout of user accounts and their last log in.

PS code:

import-module activedirectory

$domain = "domain.local"

$DaysInactive = 30

$time = (Get-Date).Adddays(-($DaysInactive))

$user = (Get-ADUser -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp | Where-Object { $_.Enabled -eq $true } | select-object Name,@{Name="Last login:"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}}  )

$userC = (Get-ADUser -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp | Where-Object { $_.Enabled -eq $true } | select-object Name,@{Name="Last login:"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} ).count

Write-host "Message: Inactive users:" $user

Write-host "Statistic: $userC"

exit 0

This gives me an output that looks like this:

pastedImage_0.png

I am looking to get it in table style like this:

Capture.PNG

but no matter what I do I cannot get the $user variable to have a new line after it.

Thanks for any help!

Parents
  • So it is possible but the Message output is returned as a single line string. Since both the web console and email are HTML based you can insert HTML formatting to your message which would then translate correctly.

    Here is a basic powershell script where i inserted some paragraph tags <p></p> between each response.

    2017-06-22 13_05_28-Edit Application Template - Powershell Message Formatting.png

    When i look at the Orion web console it creates a new line for each entry. The same *should work for email alerts too.

    2017-06-22 13_04_11-Application Component Details - Windows PowerShell Monitor.png

    So you would need to modify your script to include the <p> tags for each entry returned.

  • This was working up until this year. I wonder if the 2020.2.5 release changed this?  (now it outputs the HTML tags)

Reply Children
  • What's crazy is the "Legacy" one works just fine, but the new one is broken for HTML formatting... what I don't know is if it was broken on purpose or accidentally, and if it was on purpose what the new expected way to format that output is at this point. I wish there was some kind of directive on that when they changed things like this...