VMware vRealize Automation 8.4 – PowerShell Action Scripts: Custom VM Notes

This post is part of a series in which I am sharing my experiences using PowerShell actions to customize virtual machine deployments using VMware vRealize Automation 8.4. vRA gives you the choice to create scripts based on the following programming languages: Node.js, Python and PowerShell. I chose PowerShell because it is not (yet) commonly used in vRA and therefore deserves some attention. This post covers the script responsible for adding custom notes for a virtual machine.

What are actions in vRA 8.x?

I will not go over the entire explanation of extensibility actions in vRA but to summarize:

Extensibility actions are small, lightweight scripts of code used to specify an action and how that action is to perform. You can import extensibility actions from pre-defined vRealize Automation Cloud Assembly action templates or from a ZIP file. You can also use the action editor to create custom scripts for your extensibility actions.

In case you want to learn more about Action Based Extensibility (“ABX“), please read the official VMware documentation available here.

Why Custom Notes?

Virtual machine notes are very useful in a VMware vSphere environment as it provides additional information regarding the purpose of a particular virtual machine. This was also very much required for my customer because they wanted the requester of a new virtual machine to properly specify what applications or databases were going to be installed later on.

To add this feature during a vRA VM deployment I chose the creation of a custom ABX based on PowerShell, which is detailed in the following paragraph.

PowerShell Action Script “Custom Notes”

This PowerShell action script (“Custom Notes“) uses a single design canvas custom property and 3 additional inputs required for the vCenter Server API connectivity:

    • Virtual Machine Notes
      • Custom property “vmNotes” (string)
    • vCenter Server URL
      • Action input “vcURL” (string)
    • vCenter Server Username
      • Action input “vcUSR” (secret)
    • vCenter Server Password
      • Action input “vcPWD” (secret)


function handler($context, $inputs) {
   # Action inputs required for vCenter Server connectivity 
   $vc_URL = $inputs.vcURL
   $vc_USR = $context.getSecret($inputs.vcUSR)
   $vc_PWD = $context.getSecret($inputs.vcPWD)

   # Hostname generated during deployment
   $vm_name = $inputs.resourceNames[0]

   # Custom property from design canvas containing the VM notes
   $vm_notes = $inputs.customProperties.vmNotes
   # Connect to vCenter Server using URL and User credentials
   Connect-VIServer -Server $vchost -User $vcuser -Password $vcword -force

   # API update to set Notes for VM
   Set-VM $vm_name -Notes $vm_notes -Confirm:$false

   # Disconnect from vCenter Server
   Disconnect-VIServer -Server $vchost -Confirm:$false


 Action Subscription

To enable the new action and use it as part of my vRA project deployment, I created a new Action “Subscription” in the Extensibility section. In that new Subscription, it is important to:

    • Select “Compute post provision” for Event Topic
    • Set “event.data.blueprintId == <my-blueprint-id>” as Condition
    • Select the “Custom Notes” action script as Runnable Item
    • Add project in the Subscription scope

Final Thoughts

This was a simple but effective PowerShell script that did not take long to code. Do ensure that you trigger this action script after the virtual machine has been provisioned as part of the vRA deployment. You achieve this by using that “Compute post provision” Event Topic in the action subscription as stated above.

I hope this post is useful to those who, like me, are working with PowerShell scripting in VMware vRealize Automation 8.4.

Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.