One of my peers came up with an interesting use case today. His customer wanted to mount an existing disk on a virtual machine using a vRA Cloud day 2 action.
I couldn’t find an out of the box workflow or action on my vRO, which meant I had to do this thing from scratch.
After a quick look around I found a PowerCli cmdlet (New-Hardisk) which allowed me to mount an existing disk.
My initial attempts to just run it as a scriptable task resulted in the following error.

Hmm, so how do you increase the memory in a scriptable task? Simple, you can’t. Thus I had to move the script into an action, which does allow me to increase the memory. After some tinkering I found that 256M was sufficient to run the code.
function Handler($context, $inputs) {
# $inputs:
## vmName: string
## vcName: string (in configuration element)
## vcUsername: string (in configuration element)
## vcPassword: secureString (in configuration element)
## diskPath: string. Example in code.
# output:
## actionResult: Not used
$inputsString = $inputs | ConvertTo-Json -Compress
Write-Host "Inputs were $inputsString"
$output=@{status = 'done'}
# connect to viserver
Set-PowerCLIConfiguration -InvalidCertificateAction:Ignore -Confirm:$false
Connect-VIServer -Server $inputs.vcName -Protocol https -User $inputs.vcUsername -Password $inputs.vcPassword
# Get vm by name
Write-Host "vmName is $inputs.vmName"
$vm = Get-VM -Name $inputs.vmName
# New-HardDisk -VM $vm -DiskPath "[storage1] OtherVM/OtherVM.vmdk"
$result = New-HardDisk -VM $vm -DiskPath $inputs.diskPath
Write-Host "Result is $result"
return "It worked!"
}
Looking at the code, you will notice an input of vmName (used by PS to find the VM). Getting the vmName is actually pretty stupid simple using JavaScript. My first task in the WF takes care of this.
// get the vmName
// $inputs.vm
// output: vmName
vmName = vm.name
The next step was to setup a resource action. The settings are shown in the following snapshot. Please note the setting within the green box. ‘vm’ is set with a binding action.

Changing the binding is fairly simple. Just click the binding link, then change the value to ‘with binding action’. The default values work just fine.

The disk I used in the test was actually a copy of another VM boot disk. It was copied over to another datastore, then renamed to ‘ExistingDisk2.vmdk’. The full diskPath was [dag-nfs] ExistingDisk/ExistingDisk2.vmdk.
Running the day 2 action on deployed machine seemed to work, as the WF logs show.

So there you have a basic PolyGlot vRO workflow using PowerCli and JavaScript.
I trust this quick blog was helpful in some small way.