How to get the runbook's name inside a PowerShell Azure Automation Runbook? RRS feed

  • Question

  • Hello, I'm working on sending an email on a runbook failure and would like to capture the runbook sending the email rather than write it as a literal. I tried the usual suspects such as $MyInvocation.ScriptName, $MyInvocation.InvocationName, $MyInvocation.MyCommand, $MyInvocation.MyCommand.Name without luck. How can I grab the runbook's name within PowerShell?


    #Send failure email
    $EmailCred = Get-AutomationPSCredential -Name "Email" 
    $Subject = "{0} runbook error" -f $MyInvocation.MyCommand.Name
    Send-MailMessage -smtpServer $SMTPServer -Credential $EmailCred -Usessl -Port $Port -from $EmailFrom -to $EmailTo -subject $Subject -Body $exceptionMessage

    Wednesday, May 16, 2018 11:28 PM


All replies