-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathico_wf_execution_by_name.ps1
95 lines (80 loc) · 3.29 KB
/
ico_wf_execution_by_name.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Uncomment the following script and provide the below information to set up Intersight environment.
<#
$intersightEnv = @{
BasePath = "https://intersight.com"
ApiKeyId = "xxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxx"
ApiKeyFilePath = "C:\Users\admin\Downloads\ProductionSecretKey.txt"
HttpSigningHeader = @("(request-target)", "Host", "Date", "Digest")
}
Set-IntersightConfiguration @intersightEnv
#>
# Variables. Change accordingly
$workflow_name = 'Deploy a Virtual Machine'
$orgName = 'default'
#
# Sample Payload used by Intersight API. This is just for reference. Do not remove the comment
# We need to extract the value of the 'Input' Key and replace the $inputPayload content
<#
{
"Name": "Deploy a Virtual Machine",
"AssociatedObject":
{
"ObjectType": "organization.Organization",
"Moid": "5ddee8bb6972652d31030baf"
},
"Action": "Start",
"Input":
{
"Vcenter":
{
"Moid": "60a033446f72612d33e9f5df",
"ObjectType": "asset.DeviceRegistration"
},
"Datacenter": "/RMLAB",
"Cluster": "/RMLAB/host/Goldrake",
"Datastore": "/RMLAB/datastore/Hyperflex1",
"Folder": "/RMLAB/vm/rtortori",
"Template": "/RMLAB/vm/rtortori/ubuntu-template-hx",
"Name": "my-virtual-machine",
"Network": "192.168.130"
},
"WorkflowDefinition":
{
"Moid": "6192e224696f6e2d3124372e",
"ObjectType": "workflow.WorkflowDefinition"
}
}
#>
# This is the content of the 'Input' key in the Payload sent via API to execute this workflow.
# This is just a sample, replace with your workflow inputs
$inputPayload = @'
{
"Vcenter": {
"Moid": "60a033446f72612d33e9f5df",
"ObjectType": "asset.DeviceRegistration"
},
"Datacenter": "/RMLAB",
"Cluster": "/RMLAB/host/Goldrake",
"Datastore": "/RMLAB/datastore/Hyperflex1",
"Folder": "/RMLAB/vm/rtortori",
"Template": "/RMLAB/vm/rtortori/ubuntu-template-hx",
"Name": "test-ico-pssdk2",
"Network": "192.168.130"
}
'@
# We convert the payload string into an object
$inputDef = ConvertFrom-Json -InputObject $inputPayload -AsHashtable
# Getting the Workflow Definition based on the Workflow Display Name (Label)
$workflowDef = Get-IntersightWorkflowWorkflowDefinition -Label $workflow_name
$workflowDefRef = $workflowDef | Get-IntersightMoMoRef
# Getting the Managed Object Reference (MoRef) for the specified organization
$orgRef = Get-IntersightOrganizationOrganization -Name $orgName | Get-IntersightMoMoRef
# Create a new dictionary object that will be used by the 'AdditionalProperties' parameter when triggering the workflow execution
$inputObj = New-Object System.Collections.Generic.Dictionary"[String,Object]"
$inputObj.Add("Input",$inputDef)
# Execute the workflow (create a request, that is a WorkflowInfo)
$wfExec = New-IntersightWorkflowWorkflowInfo -Name "Deploy a virtual machine" `
-AssociatedObject $orgRef -Action Start `
-AdditionalProperties $inputObj -WorkflowDefinition $workflowDefRef
# Display Name of the request, Moid and user
$wfExec | Format-Table -Property Name,Moid,Email