|This Feature was released as part of version 2.8.0.|
Note: This article describes in-detail Azure Runbooks scripted actions.
See the Scripted Actions Article for General information on scripted actions.
Azure Runbook scripted actions are run via an Automation Account in Azure. This enables automated actions of Azure Resources outside of the VM.
Use-Case for Azure Runbook
For some automations, the necessary actions to take must be done in the context of Azure, outside of the VM itself. While these commands could be run on the VM with the Azure PowerShell module installed, running scripts on session hosts that target azure are less efficient and can be unreliable. Azure Automation allows for consistent execution, and allows for the NMW-App to run the scripts as itself easily. Some Scripts even require the VM to be restarted or shutdown, which means it could not be run on the session VM regardless.
Enable Azure Runbooks
In order to execute PowerShell in azure, a new automation account must be made for the NMW app to use. Because this creates new Azure resources, we have made the Azure Runbooks feature require manual activation.
1. Go to Settings -> Nerdio Environment
2. Go to Azure runbooks scripted actions and click "Disabled" Hyperlink
3. Toggle the switch to "On" and wait for the creation process.
Considerations for Nerdio's Azure scripted actions
Although NMW uses Azure Runbooks, some general conventions and common procedures used for runbooks are not applicable. If you are familiar with using Azure Runbooks in the past, you will need to keep in mind these key considerations:
1. There is no need to specify authentication, such as authenticating using the RunAs account or passing a credential. By the time the actual code in the scripted action is executed, NMW has already logged into Azure and no additional authentication is required. Simply create the script as if it is being run after already having used Connect-AzAccount. Keep in mind this means that the NMW service principal will need the appropriate permissions on resources it will attempt to alter.
2. Az Modules are already installed. If you require a specific version, alter the modules attached to the automation account. Any other modules needed will require installation as well.
3. Some Variables will be defined prior to your code. This is useful to get necessary parameters, such as the VM name, Subscription the VM is in...etc. You can view the variables by hovering over the info Icon next to "script":
4. It is beneficial to have commands that result in an error exit out of the script entirely, so that the Run job results in "fail" instead of "Complete", which is relayed to Nerdio. To do this, include
$errorActionPreference = "Stop"
If a script does not preform the actions desired, it may still return "Complete". This simply means that the powershell script itself did not encounter fatal errors. You can view the output of the script via nerdio like so:
The output tab will show output from the script. However, not all information is shown. It may be beneficial to go to the Azure portal and find the log which matches the timestamp to see more info, as described below.
How the process works in Azure
When an Azure scripted action is run, the associated automation account runs a specialized runbook, which copies the code directly from the Nerdio app and executes it.
You can see this runbook when navigating to the Automation Account:
And as such, all scripts are executed as the same job.
If we are looking for errors, we can view the log with the timestamp that matches what is in Nerdio's task log:
Here we can see that our script was failing due to an invalid keyvault name. Your errors will be different depending on your script.