How to fix error for azure automation

Navaska 25 Reputation points
2024-04-30T23:07:50.5066667+00:00

Hi there,

I have setup an automation app to stop and start a stream analytics job, following a guide from this doc https://learn.microsoft.com/en-us/azure/stream-analytics/automation-powershell

Whenever the job is running, the runbook runs fine to stop it, yet once it is stopped it and then the runbook runs again, constantly pulls this error below.

"Cannot find an overload for "op_Subtraction" and the argument count: "2". (Cannot find an overload for "op_Subtraction" and the argument count: "2".)".

Am using powershell 7.2.

Any help would be appreciated.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,140 questions
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 20,431 Reputation points
    2024-05-01T07:05:01.63+00:00

    @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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful