Struggling with Logging in Azure Automation Runbooks

0
0
Asked By TechieNinja42 On

Hey everyone! I'm new to PowerShell and have started using it in Azure Runbooks to automate tasks with Excel files and blob storage. I'm having a tough time figuring out how to log outputs clearly within Azure. For instance, I usually use 'print' in Python for quick debugging, but when I use 'write-output' inside a function, it doesn't seem to return anything. Outside of functions, it's fine. Are there specific differences between Azure PowerShell runbooks and regular PowerShell that I should know about? Also, any tips or resources for effective debugging in Azure Automation would be much appreciated since I'm still learning! Thanks!

4 Answers

Answered By AzureGuru88 On

Switching to 'Write-Verbose' with '$VerbosePreference = "Continue"' at the start of your script is my go-to for logging in Azure. The docs provide some great tips for this. If you miss your 'print' from Python, 'Write-Host' could be your answer for debug prints in Azure.

AshenRider12 -

Just out of curiosity, where does the output of the Verbose stream show up in RunBooks? I think it’s only visible when testing, right?

ScriptFanatic45 -

Yeah, you're correct! It doesn’t show up in the job results, which can be a bit annoying.

Answered By ScriptMaster101 On

I usually go for 'write-output' and 'write-error'. When writing inside a function, remember that if you're assigning the output to a variable, it won't show up in the output stream. Instead, you might want to check out the official docs on Azure Automation for more details on output streams. Here’s a link to help you out: https://learn.microsoft.com/en-us/system-center/sma/overview-runbook-messages-output?view=sc-sma-2025&tabs=WarningError

CuriousCoder99 -

Got it! So using 'write-output' inside a function won’t print to the main output. Just to clarify, if I need to log something inside a function, sticking with 'write-Verbose' might be a better option, but that adds more noise than 'write-output', right?

PythonLover23 -

Exactly! And 'write-Host' seems to never show anything in Azure, while it works fine locally. Weird how it differs!

Answered By CommandLineWizard On

Just a heads up, "write-Output" and "Write-Host" behave differently in PowerShell. 'Write-Output' goes to the success stream, which you can capture, while 'Write-Host' is for displaying info directly, not capturable. Check out the 'about_redirection' topic for more stream info!

Answered By PowerShellPro On

For Azure Automation, I’ve found 'write-warning' really useful. 'Write-Verbose' can log way too much, which slows things down for me. Using 'write-warning' keeps things clear and simple.

EfficientDebugger91 -

Exactly! 'Write-Warning' stands out and is perfect for when you want quick visibility in job run outputs.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.