This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

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.

Reply
  • 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.

Children