#==================================================================================
# Sub: LogDebugEvent
# Purpose: Logs an informational event to the Operations Manager event log
# only if Debug argument is true
#==================================================================================
Function Log-DebugEvent
{
param($eventNo,$message)
$message = "`n" + $message
if ($debug -eq $true)
{
$api.LogScriptEvent($SCRIPT_NAME,$eventNo,$EVENT_LEVEL_INFO,$message)
}
}
#=====================================================================================
# Convert epoch timestamp into human timestamp.
Function get-epochdate ($epochdate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochdate)) }
#=====================================================================================
# Start script by setting up API object.
$api = New-Object -comObject 'MOM.ScriptAPI'
$message = "Script started with parameters $regKeyPath, $regValue, $timeStampType, $threshold, $debug"
Log-DebugEvent $SCRIPT_STARTED $message
# Determine amount of days between regValue date and currentDate.
$currentDate = Get-Date
$daysOld = (New-TimeSpan –Start $timeStampDate –End $CurrentDate).TotalDays
$daysOld = [math]::Round($daysOld,1)
# Put the gathered data into the property bag.
$bag = $api.CreatePropertyBag()
$bag.AddValue('TimeStampDate',$timeStampDate)
$bag.AddValue('DaysOld',$daysOld)
$bag.AddValue('ErrorMessage',$errorMessage)
$bag.AddValue('Threshold',$threshold)
$message = "DatDate is: $timeStampDate`nDaysOld is: $daysOld`nErrorMessage is: $errorMessage"
Log-DebugEvent $PROPERTYBAG_CREATED $message