Check Updates to file

It bounced an error:

Method invocation failed because [System.String] does not contain a method named ‘AddMinutes’.
At C:\powershell\check_file_and alarm.ps1:36 char:9

  • if ($prevupdate -and ($update.Update_Date_Time -gt $prevupdate.Ad …
  • CategoryInfo : InvalidOperation: (:slight_smile: , RuntimeException
  • FullyQualifiedErrorId : MethodNotFound

The $prevupdate – Addminutes not available.

any thoughts?

 

Thanks for all your help mush apricated.

[quote quote=288982]The $prevupdate — Addminutes not available.

any thoughts?

Thanks for all your help mush apricated.

[/quote]
Yep, the error message tells you everything you need. It says “[System.String] does not contain a method named ‘AddMinutes’.” That tells us that $prevupdate is a string object and not a datetime object.

With that info, move to where $prevupdate is defined and we see this

$prevupdate = $update.Update_Date_Time

Looks like when we import the data from your csv, it treats this column as a string and not a datetime. So lets try to change that. See Get-Help about_type_accelrators

 

$prevupdate = [datetime]($update.Update_Date_Time)

Give this change a shot and we’ll see if that fixes it.

that worked perfect does there have to be some math now for $gaps time1 versus time2?

Thanks!!

[quote quote=289054]that worked perfect does there have to be some math now for $gaps time1 versus time2?

Thanks!!

[/quote]
We did the math. Look at line 4 of my post above (#288304). The variable $Gaps should now contain every instance where time between rows is greater than exactly 15 minutes. Now just do what you want with that data. Remember this is exactly 15 minutes so if slight variation is acceptable, I would recommend changing the threshold (maybe 16 min).

Mike,

Maybe it’s my misunderstanding, but I thoughts $gaps would only be produced if there was a 15\16 minute interval delay in one of the records. It looks like it just list all of the recorded entries. The output below grabs current time(Time1) and first entry in file(Time2) and displays which that would be a gap, but
the next entry is wouldn’t be a gap since both entries are taken 1 minute after midnight.

Normal Processing
Time1 Time2


1/30/2021 8:34:23 AM 2021-01-30 00:00:58
1/30/2021 12:00:58 AM 2021-01-30 00:01:58

Thanks for ALL your help…

 

Is there a place to mark as Answered?

 

Thanks.