@Navaska, thank you for posting this question on Microsoft Q&A.
I reviewed the script lines which is causing this error, and it appears to be related to the Value key used here - $_.EventName.Value
The $_.EventName
is of String datatype. For more details see, the output in code snippets below:
# - Get the record from Activity Log
PS D:\> $Activity_log = Get-AzActivityLog -MaxRecord 1
# - Examine, whether the Eventname.Value contains anything - NO
PS D:\> $Activity_log.Eventname.Value
# - Eventname property is of type "String" which does not have a "Value" property
PS D:\> $Activity_log.Eventname.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
# - to get the correct eventname - just use "Eventname"
PS D:\> $Activity_log.Eventname
End request
Thus, the line containing Get-AzActivityLog
should be modified to the following (else, there is always a comparison of "null" with string "Stop Job*" which is always false, resulting in $stopTimeStamp to be empty/null.
$stopTimeStamp = Get-AzActivityLog -ResourceId $resourceId -MaxRecord 1000 -WarningAction Ignore | Where-Object {$_.EventName -like "Stop Job*"}
Hope this helps.
If the answer did not help, please add more context/follow-up question for it. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.