I am attempting to set this up and want to see what I am missing. 2 issues I see ... 1 - it doesn't run 2 - it is slow to load the sqlps module
Set-Executionpolicy UnRestricted -force
Import-Module sqlps -DisableNameChecking
$DataDate = Invoke-Sqlcmd -Query "select top (1) date_timestamp from tbl_data where desc_id like 'OFF%' order by date_timestamp desc;" -Database "Prd_INTEG" -U "SQLMonitor" -P "Password"
$CurrentTime = Invoke-Sqlcmd "SELECT GETDATE() AS TimeOfQuery;"
$TimeDiff = New-Timespan -Start $DataDate.Date_timestamp -End $CurrentTime.TimeOfQuery
if ($TimeDiff.TotalHours -gt 6) { $mon.FireActions = $true $mon.Details = "No Data in $TimeDiff.TotalHours hours" } else {$mon.FireActions = $false}