I have a Powershell Custom sensor which performs a scan of ..., every 5 minutes or so, i want to be able to display when it has run ie today's time, but i am having problems with the output - here is a snippet of my current code, but i would either like to display the value as 'Time' or as a string rather than as a real number
- Now Display how long since last scan - Compare current time with time of last Record
$lastscan = Get-Date -Format "yyyy/MM/dd HH:mm:ss" # Time Now $midNight = Get-Date -Hour 0 -Minute 00 -Format "yyyy/MM/dd HH:mm:ss" # Midnight $timeDiff = new-timespan -start $midNight -end $lastscan # Calc diff as Structure of Times
- Days : 0
- Hours : 16
- Minutes : 3
- Seconds : 0
- Milliseconds : 0
- Ticks : 577800000000
- TotalDays : 0.66875
- TotalHours : 16.05
- TotalMinutes : 963
- TotalSeconds : 57780
- TotalMilliseconds : 57780000
- Convert Returned Time Into hh:mm for readability
[string]$timeDiffS = ([string]$timeDiff.hours).PadLeft(2,'0') + '.' + ([string]$timeDiff.minutes).PadLeft(2,'0') Write-Host ' {' Write-Host ' "channel": "'zTimeOf Last Scan'",' Write-Host ' "unit": "Hours",' Write-Host ' "mode": "Absolute",' Write-Host ' "showChart": "1",' Write-Host ' "showTable": "1",' Write-Host ' "warning": "0",' Write-Host ' "float": "1",' Write-Host ' "decimalmode": "2.2",' Write-Host ' "value": "'$timeDiffS'",' Write-Host ' "LimitMaxError": "99999",' Write-Host ' "LimitMaxWarning": "9999",' Write-Host ' "limitmode": "0"' Write-Host ' },'
i would like it to be HH:MM, but i have to go with HH.MM and if there is a trailing 0 i get HH.M How can i recode this to get the format i require PS i know its messy and inefficient, but it works Optimisation can come when its all working correctly
Add comment