FacebookTwitterDiggGoogle BookmarksRedditTechnoratiLinkedinRSS Feed
Pin It

Calling Powershell/PowerCLI Scripts from a vCAC Workflow

Video Coming Soon!  VMware vCAC is able to call PowerShell scripts from it's workflow. To alter a workflow, you need to have the vCAC Designer tool installed (instructions coming soon).

Install Script into Repository

You can run any PowerShell script that you like, but most likely there will be some variables you will want to pass from vCAC to the script. For this example, we will be working with a very simple script that just requires the VM name as an input parameter. Such a script would be saved in a .ps1 file and look like:

{codecitation}## Assign properties from vCAC to variables to be utilized as part of our script.


$Hostname = $Properties["VirtualMachineName"]


## your script goes here
Write-Host $Hostname


1. Open the command prompt on the vCAC server and change the directory to C:\Program Files (x86)\DynamicOps\Design Center
2. Import the ps1 file into the vCAC Repository by making the following command: "Cloudutil.exe File-Import -n <Name for file in vCAC repository> -f <ps1 file location>"
3. Check to make sure that the file made it into the repository by running the following command: "Cloudutil.exe File-List". You should see the name you gave the file in step 2 where you entered the <Name for file in vCAC repository>

 Install Script Into Repository

Alter the vCAC Workflow

1. Open the vCAC Workflow designer and press the load button at the top
2. Choose a workflow stub to alter. All of these stubs are called at different times during the life cycle of the machine. Unless you have a specific stub in mind, use the "WFStubMachineProvisioned" stub which will run your script after the machine has been provisioned.
3. In the workflow window, double click on the "Machine Provisioned" box

Navigate to Custom Code in Designer

4. In the workflow window, double click on the "Machine Provisioned" box

Navigate to Custom Code in Designer
5. Double click "Custom Code" Navigate to Custom Code in Designer
6. If you haven't modified this workflow before, all you will see is a start task. For just the basic example, we're going to only pass the VM name to the PowerShell script, so we will need to grab that value by dragging the "GetMachineName" activity from the toolbox on the left, to the work space. 
7. Connect the start activity to the "GetMachineName" activity by hovering over the start activity until you see a grey box, then drag that box down to the GetMachineName activity
 Add Get Machine Name Activity

8. Double click on the "GetMachineName" activity and enter the following information:
     Machine Id = "virtualMachineId"
     Machine Name = "vmName"

*Note* you will see a red exclamation mark denoting that there is an error, but that will go away in the next step

Configure Machine Name Activity

9. At the bottom of the window, click the tab that says "Variables" to expand out the variables window.
10. Click on "Create Variable" and enter "vmName" for the variable name

*NOTE* the red exclamation mark should now be gone

Create Variable

11. Go back to the work space by clicking on the "Custom Code" breadcrumb
12. Drag an "A + B Assign" activity from the toolbox on the left under the Primitives header and link it to the GetMachineName activity
13. Enter the following information into the activity:
     First Box = args("VirtualMachineName")
     Second Box = vmName

*NOTE* you will see a re exclamation mark in for the first box. This will go away in the next step

A+B Activity
14. In the variables tab below the work space, press "Create Variable"
15. Give the variable a name of "args"
16. use the "Variable Type" drop down to choose "Browse for Type"

17. Type "Dictionary" into the "Type Name:" field and select "Dictionary<TKey,TValue>"
18. You should now see the "System.Collections.Generic.Dictionary" fields appear near the top with two drop down boxes. Click the down arrow and select "String" for both boxes, and click OK.
19. *IMPORTANT* you need to initialize the args array. To do this, put the following into the "Default" column for the args variable: New Dictionary(Of String, String)
Set Variable Type
20. Drag an "ExecutePowerShellScript" activity from the left side toolbox under the DynamicOps.CDK.Activities (must have the CDK license) header.
21. Connect the "A + B Assign" activity to the "ExecutePowerShellScript" activity
Add Exectute PowerShell Script Activity

22. Double click the "ExecutePowerShellScript" activity and enter the following information:
     Script Name = "<Name for file in vCAC repository>" (Must include quotes)
     Machine Id = virtualMachineId
     Arguments = args

Configure PowerShell Script Activity

23. To save the workflow, press the "Send" button in the top toolbar

Send the Workflow to Save

Next, you should check out the article on how to call this workflow from a blueprint when it's requested: Call a vCAC Workflow Stub During Provisioning