Getting output from CustomScriptExtension

There are times when it is important to get relevant information from the output generated by a PowerShell script to know more about the execution and even obtain return values. Luckily, it is possible to read the output of a Custom Script Extension, as shown in the next code listing. In this example, an outputs section has been added, which in turn uses the inbuilt reference function to retrieve values from the customscriptextension resource.  The output from this resource contains properties that help in retrieving the values. The code for this example is available in the CustomScriptExtension-outputs.json file in the accompanying chapter code:

{
"name": "[concat(variables('vmName'),'/','firstCustomScriptExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2016-03-30",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
],
"tags": {
"displayName": "firstCustomScriptExtension"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat(parameters('storageAccountName'), '/', variables('firstCustomScriptExtensionScriptStorageContainer'), '/', variables('firstCustomScriptExtensionScriptFileName'))]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstCustomScriptExtensionScriptFileName'), ' -featureName web-server -serviceName w3svc')]"
}
}
}
],

As you can see in the following example, the outputs section provides information about the messages generated by code that has been executed after the deployment of a virtual machine:

  "outputs": {
"customScriptOutput": {
"type": "string",
"value": "[reference('firstCustomScriptExtension').instanceView.substatuses[0].message]"
}
}

The output from this execution is shown in the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.152.87