6

I want to write info logs into Azure Automation job logs. I've created the simple PowerShell runbook

$InformationPreference = "Continue"
Write-Information "Hello info" 
Write-Verbose "Hello Verbose"
Write-Warning "Hello warning"
Write-Error "Hello error"

And in runbook execution All logs I see only verbose, warning and error logs

enter image description here

If to disable runbook Verbose logs I see only warnings and errors. Locally it works fine but not in Azure. I've also tried Write-Information "Hello info" -InformationAction Continue - didn't help.

Write-Information appeared in PowerShell 5.0. I've checked the PS version in Azure Automation sandbox machine by using $PSVersionTable - it's more than 5. So, should work.

Do you know if they support it or not?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Vasyl Zvarydchuk
  • 3,789
  • 26
  • 37

3 Answers3

4

If you want to write info logs into Azure Automation job logs, I suggest you use write-output. For details, you can refer to this article.

I'm not sure if write-information is supported or not in runbook. I test it at my side, as well as I test the cmdlet write-host which is a wrapper for write-information. But no message output for both of them.

A support ticket is raised for confirmation from MS.

Hope this helps.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • 9
    `write-output` has a huge drawback - you can't use it in functions which returns something. For instance `function Foo() { Write-Output 'One'; return 1 }` will return an array. And `return something` is actually translated to `write-output something; return`. So, it's very sad that AA doesn't support Info. – Vasyl Zvarydchuk Jan 20 '19 at 06:18
2

Azure Automation does not fully support the Information stream at this point. PowerShell 5 support is not enough: your runbook will not fail, but Automation will not capture and store the Information stream content, and this is why you will not see it in the logs.

Anatoli Beliaev
  • 1,614
  • 11
  • 13
2

I do wish Write-Information was available in Azure Automation.

Using Write-Output in a function that you want to return something else (like a Boolean) is quite problematic.

user3019895
  • 71
  • 1
  • 6