Hi there, I'm trying to find if a user is still using his VM by pulling his last logon and I'm having trouble with the output. When I run it in PS it works as expected, but in Prtg it only shows the message text without the date of last loogin. Here's the code :
Import-Module ActiveDirectory
$value=1 $server=$env:COMPUTERNAME $LogonDate=Get-ADComputer $server -Properties LastLogonDate | select -ExpandProperty LastLogonDate $LogonDateString=$LogonDate.ToString() $DaysPassed=(New-TimeSpan -Start $LogonDate -End (Get-Date)).Days if ($DaysPassed -gt 60 ) {$value=0 $message="Vm was not used for more then 60 days, last Logon was on " + $LogonDateString} else { if ($DaysPassed -le 60 ){ $value=1 $message="Vm is in use, last Logon was on " + $LogonDateString}}
Write-Host @" <prtg> <result> <channel>Vm in use</channel> <value>$value</value> </result>
<text>$message</text> </prtg> "@
Add comment