VMware Cloud Community
progsaz
Contributor
Contributor

Pass a Custom Property from vRA to vRO and then execute a powershell command using the Custom Property

I have a Custom Property defined in vRA called PatchPhase (Drop Down List).  I want to use the results of Patch Phase and use vRO to execute a PowerShell command that has an If\Then command.

If ($PatchPhase -eq "Phase_I") {Write "User Selected Patch Phase I")}

The Powershell script works by itself if I supply the variables

I can use vRO to Read the vRA properties and log them

What I cannot do is send the Custom Property to the Powershell command.

I have greater goals but would like to see the powershell work with the Custom Property to start.

Thanks for any help

Scott

5 Replies
GrantOrchardVMw
Commander
Commander

You'll want to do something like this to create the command, then pass it to your "execution" workflow. Is that what you're aiming for?

pastedImage_0.png

Grant

Grant http://grantorchard.com
Reply
0 Kudos
pankajchhabra
Enthusiast
Enthusiast

Hello,

I think what you might be seeing is that powershell command passes, but when you see the properties of the VM, they will still be old.

My take is that you will need to use reconfig_VMTask to do this. For this you will need to power down VM in your script, set the parameters to reConfigVM_Task and power on the VM. I have used reConfigVM_Task and it works.

See this also - ReconfigVM_Task | VMware and Powershell

Thanks,
Pankaj

Reply
0 Kudos
progsaz
Contributor
Contributor

Looks like I found one of my issues.  The PowerShell script needs a line that references the Property parameters

param(

PatchPhase)

I am still working on getting the Custom Properties to go correctly.  I think my issue now may be the scripting in vRO.  I am trying to send $PatchPhase to my powershell.  Below is what I have in my Scripting tab right now

//Log input variables for troubleshooting purposes
System.log("Workflow started from workflow stub " + externalWFStub + " on vCAC host " + vCACHost.displayName);
System.log("Got vCAC virtual machine " + vCACVm.virtualMachineName);
System.log("Matching virtual machine entity " + vRAEntity.keyString);


var VM = vRAEntity.getInventoryObject();
System.log("VM Name is " + VM);

if (VM != null)
{
var vmEntities = vRAEntity.getLink(vCACHost, "VirtualMachineProperties");
var vmProperties = new Properties();

//Loop through all of the VM Properties and log them for reference.
for each (var vmEntity in vmEntities)
  {
  var Name = vmEntity.getProperty("PropertyName");
  var Value = vmEntity.getProperty("PropertyValue");
  vmProperties.put(Name, Value);
  System.log("INFO: " + " PropertyName " + Name + " propertyValue " + Value);
  }

// Set Output variables so they can be used in additional workflows
var Output = vmProperties.get("VirtualMachine." + OutputProperty);
vmName = vCACVm.virtualMachineName;
//Log the value for troubleshooting purposes
System.log("INFO: Output Property is " + Output);

Reply
0 Kudos
progsaz
Contributor
Contributor

after more testing it seems that my Parameter is being sent to the powershell script but the value is blank.

Reply
0 Kudos
future2000
Enthusiast
Enthusiast

Hi Progsaz,

Use the System.log(paramaterName) in your scriptable task to verify the custom property has content in Orchestrator.

Are you using the invoke an External Powershell script workflow?

If so make sure your Arguments are being passed correctly. I use a simple bit of javascript like this to pass a few properties along to the Powershell script.

The following code populates the scriptArgs attribute. The contents of this, which in my case is the VM IP Address and DNS name, is then passed out as an Out Attribute and into the Invoke an External script workflow as the arguments in parameter.

scriptArgs = virtualMachineProperties.get("EBS.MachineProvisioned.IPAddress") + " " + vCACVm.vmDNSName;

System.log(scriptArgs);

I then log scriptArgs in that second line to make sure the content is what my executed powershell script would expect.

In your case you would use something like this...

scriptArgs = vCACVm.customproperyname

You've already parameterized the powershell code so you are nearly there, the param section in your script will take the arguments in order. Let me know if you want an example workflow I'm using to do this kind of thing. I'm using vRA 7 and the EB now so my properties are different from yours. It all depends on what you bind to your scriptable task, assuming your using the respective extensibility template.

Cheers