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!