Scripted Actions - Azure Runbooks - Powershell Output

When using Scripted Actions (SA) or Azure Runbooks (AR) the output from the task details is very limited. Sometimes not even seeing the output from Write-Host statements. Very difficult to debug. What can I do get output from these scripts? AI has suggested doing log output to text files in an  Azure Blob, or Log Analytics. Looking for feedback on best way to handle this. 

Lonnie

1

Comments (3 comments)

0
Avatar
John Tokash

I can speak to Azure Runbooks, you have to use write-output, instead of write-host.    But can you give an example of something that isn't providing the output to the log you were looking for?

I use outputs for logging and debugging misbehaving runbooks, and write-output usually does the trick - For runbooks at least, the log is written to the NMM detail log unless its nested in something other than the runbook I was trying to execute.   Its been a while since I've had to focus on it, but I'd say give that a shot first.

0
Avatar
Lonnie Thibodeaux

HI John, 

Well first of all, originally in my script, I was using Write-Output for most everything, just comments as the script processing was done. That wasn't showing up in the details of the task, so I changed that to Write-Host. That did not work either. In my recent support ticket, I asked: 

Another thing about all this is, is there any information that describes how to debug these scripts?  There is neglible output in the task details.  ChatGPT provided instructions on creating blog storage and output text file(s) from the script. Is that the way to get some kind of log?

The reply: 
Regarding the script debugging, this is not something that exists within Nerdio, the expectation is that scripts would be thoroughly tested before being added to Nerdio. Nerdio should be seen as a tool to run the script, not to built/debug it.  

So according to Nerdio support, it doesn't seem they capture script output in the task details.  With most of the scripts I've put into Nerdio, I don't remember seeing much in the way of output in the task details. 

One other thing. During some recent script testing (another scenario, not this one). I found that Write-Output is not always the best cmdlet to use for providing script status as it executes. The output gets mixed into the Output Stream. So when I had something like this below in a function:

$process = Start-Process…some process
Write-Output “Some Text” 
return $process.exitcode 

I was not getting the correct value from the function return. Don't use the above as a concrete example, but it was something like that. I had to change to Write-Hosts in order to get my process return values. 



 

0
Avatar
Jacob Reinhardt

I want to re-energize this. While the original request may have focused on need to output to the correct stream, I want to reinforce that there is need for better output options in the Scripted Actions. A mechanism by which Nerdio could provide a downloadable log or something easier to read in the UI would be very helpful. It would take a creative approach to how the Azure Automation bootstraps the underlying scripted action, but I'm confident that Nerdio could develop a feature if they saw the value that woudl provide better structured outputs from scripted actions.

Please sign in to leave a comment.