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:
I am looking to get it in table style like this:
but no matter what I do I cannot get the $user variable to have a new line after it.
Thanks for any help!