Azure PowerShell Runbook - Error output details column empty - azure

I have an Azure PowerShell 7.1 runbook in an automation account that is executing as expected. The only issue I have is that my Error Output within the running job screen is always missing the details column. This means I have to click on each record to see what is in it, which is very tedious.
Note: I am using the Write-Error command to generate these messages inside a try/catch
You can see what I mean in the following picture:
Any help would be greatly appreciated.

Only the graphical PowerShell runbook type allows you to see the details column. After trying a workaround, I found a solution using a graphical PowerShell runbook.
I created a graphical PowerShell runbook and added my PowerShell onto the canvas. It was successfully executed and the following output with job details were displayed:
Aside from the runbook messages, you can also add Input and Output, as shown in the image below.
I've just executed a sample write-error command.
Write-Error "Hi"
Automation Account -> Runbook (type:Graphical Powershell Runbook):
Output:

Related

Running Azure Powershell Inline Script

I have a powershell script in order to make a backup of a SQL Database. I run the script locally, i run the script on TFS release phase with Powershell Script (not the azure powershell task), and everything went well.
Now, i want it to run it with the Azure PowerShell script: InlineScript because i want to remove the login part from my powershell. I saved the username \ password in the variables in order to login and i want to get rid of that
This is the script :
Please notice that i put the Login-AzureRmAccount because of the error. After this, i'm still getting it.
Error message:
[error]Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
[error]Run Login-AzureRmAccount to login.
As mentioned above please change the dropdown to "Azure Resource Manager" because in Azure classic this command will translate to Start-AzureSqlDatabaseCopy which does not have all the options available
https://learn.microsoft.com/en-us/powershell/module/servicemanagement/azure/start-azuresqldatabasecopy?view=azuresmps-4.0.0

Azure powershell runbook don't show any output

I have a simple Azure PowerShell runbook script
workflow CheckIdentityColumns
{
Write-Output "Test Output"
}
When I am trying to test it I don't see any output.
Why?
This is because your flow is Powershell runbook not Powershell Workflow runbook .
In Powershell runbook, you don't need to use
workflow CheckIdentityColumns{}
declaration. This is the main reason why it doesn't work.
I tried your scenario and it worked for me. You can view the details below.
This happened to me in different scenario. The answer I got from Microsoft support was that the Runbook in the cache is still the older one, i.e. an empty Runbook in your case. All you need to do is:
Publish the Runbook and edit and test again
If it still doesn't work then clear the cache and restart your browser
Test Runbook:
Output:

Does Azure Automation support Write-Information?

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
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?
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.
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.
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.

VSTS Build Succeeded even ARM Template was invalid

Am working on Azure Resource Manager Templates(ARM Templates) and VSTS CI&CD. With the help of ARM Templates, I want to deploy AKS (Azure kubernete Service). So before going to deploy, I need to validate my ARM Template in the CI-Build by applying a PowerShell task. But here, at the time of validating my ARM Template “It’s not stopping CI-Build even when the validation fails”. Its giving output as “Validation Completed” as shown in the below picture . Is there any solution to resolve this issue, i.e. I wanted to stop my CI-Build running if any validation fails.
Not sure how does your powershell script look like. But according to the screenshot, the powershell script is executed successfully without any error code return. You can update your powershell script to check the validate result and set the exit code to "1" if the result is "InvalidTemplate". This will make the powershell task fail when the template is valid.
Looks like the resource is defined multiple times in the template. You can remove it and its always a good practice from the PowerShell script to use Test-AzureRmResourceGroupDeployment and validate if the template is valid and has obtained all its parameters and then deploy using New-AzureRmResourceGroupDeployment
Like Eddie said you can try this inside a try{} catch block and return an exception or an exit code to make the VSTS Build pipeline fail, if the script fails.

azure runbook get who executed the job

I was working with azure runbooks in automation accounts for quite a while but recently I was tasked to identify who was executing the runbook.
I noticed that there is a fied called "Executed by" when you get information from a job, but seems that field is being removed by MSFT.
Checking the logs I can see the calls to the runbook but the job id stated in the log doesn't match the one in the jobid in the runbook inside the automation account.
I was wondering how can I match an execution on a runbook with a entry in the log.
any idea with powershell or by calling the REST API directly?
Thanks!
You can get the user who started the Automation job using the startedBy field returned in the Get-AzureRmAutomationJob and REST API.
This will require passing in the job id, which you can get using:
$PsPrivateMetadata.JobId.Guid

Resources