I would like to print out the name of the currently running runbook.
"Printing runbook name"
$MyInvocation.MyCommand.Name
"Printing call stack info"
$MyInvocation.MyCommand
the above does not work and just returns blank. Has anyone else got this to work?
Thanks
$Myinvocation
automated variable contains mainly the current call stack information as detailed in the given MS Doc. Make sure that you are not using it in an inline script. Because$MyInvocation
is not available inInlineScript
blocks, so you can't use it within anInlineScript
.Sometimes it doesn't work if you are using it along with the PowerShell function scripts and also PowerShell workflows in an automation account. And also check that you have PowerShell version updated to the latest releases.
I tried below command in my automation environment and was able to retrieve the current runbook name as shown.
If still the issue persists, try using below alternative approach using
Get-AzAutomationJob
command. You will be able to retrieve the runbook name with the help ofJobID
as explained below.