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
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.
Yeah, you're correct! It doesn’t show up in the job results, which can be a bit annoying.
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
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?
Exactly! And 'write-Host' seems to never show anything in Azure, while it works fine locally. Weird how it differs!
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!
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.
Exactly! 'Write-Warning' stands out and is perfect for when you want quick visibility in job run outputs.
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?