5.5.2
Table Of Contents
- Using VMware vCenter Orchestrator Plug-Ins
- Contents
- Using VMware vCenter Orchestrator Plug-Ins
- Introduction to Orchestrator Plug-Ins
- Configure the Orchestrator Plug-Ins
- Using the vCenter Server Plug-In
- Configuring the vCenter Server Plug-In
- vCenter Server Plug-In Scripting API
- Using the vCenter Server Plug-In Inventory
- Access the vCenter Server Plug-In Workflow Library
- vCenter Server Plug-In Workflow Library
- Batch Workflows
- Cluster and Compute Resource Workflows
- Custom Attributes Workflows
- Datacenter Workflows
- Datastore and Files Workflows
- Datacenter Folder Management Workflows
- Host Folder Management Workflows
- Virtual Machine Folder Management Workflows
- Guest Operation Files Workflows
- Guest Operation Processes Workflows
- Power Host Management Workflows
- Basic Host Management Workflows
- Host Registration Management Workflows
- Networking Workflows
- Distributed Virtual Port Group Workflows
- Distributed Virtual Switch Workflows
- Standard Virtual Switch Workflows
- Resource Pool Workflows
- Storage Workflows
- Storage DRS Workflows
- Basic Virtual Machine Management Workflows
- Clone Workflows
- Linked Clone Workflows
- Linux Customization Clone Workflows
- Tools Clone Workflows
- Windows Customization Clone Workflows
- Device Management Workflows
- Move and Migrate Workflows
- Other Workflows
- Power Management Workflows
- Snapshot Workflows
- VMware Tools Workflows
- Using the Configuration Plug-In
- Using the vCO Library Plug-In
- Using the SQL Plug-In
- Using the SSH Plug-In
- Using the XML Plug-In
- Using the Mail Plug-In
- Using the Net Plug-In
- Using the Enumeration Plug-In
- Using the Workflow Documentation Plug-In
- Using the HTTP-REST Plug-In
- Using the SOAP Plug-In
- Using the AMQP Plug-In
- Using the SNMP Plug-In
- Using the Active Directory Plug-In
- Using the Dynamic Types Plug-In
- Configuring and Using the Multi-Node Plug-In
- Using the PowerShell Plug-In
- Using the PowerShell Plug-In Inventory
- Configuring the PowerShell Plug-In
- Running PowerShell Scripts
- Generating Actions
- Passing Invocation Results Between Actions
- PowerCLI Integration with the PowerShell Plug-In
- Sample Workflows
- Access the PowerShell Plug-In API
- Working with PowerShell Results
- Examples of Scripts for Common PowerShell Tasks
- Troubleshooting
- Index
n
If the returned object is of type complex, the object is represented as PSObject.
Examples of Scripts for Common PowerShell Tasks
You can cut, paste, and edit the JavaScript examples to write scripts for common PowerShell tasks.
For more information about scripting, see the vCenter Orchestrator Developer's Guide.
Example: Run a PowerShell Script Through the API
You can use JavaScript to run a PowerShell script through the API of the plug-in.
This example script performs the following actions.
n
Opens a session to a PowerShell host.
n
Provides a script to run.
n
Checks invocation results.
n
Closes the session.
var sess;
try {
//Open session to PowerShell host
var sess = host.openSession()
//Set executed script
var result = sess.invokeScript('dir')
//Check for errors
if (result.invocationState == 'Failed'){
throw "PowerShellInvocationError: Errors found while executing script \n" +
result.getErrors();
}
//Show result
System.log( result.getHostOutput() );
} catch (ex){
System.error (ex)
} finally {
if (sess) {
//Close session
host.closeSession( sess.getSessionId() );
}
}
Example: Work with Result
You can use JavaScript to work with the result of a PowerShell script run.
This example script performs the following actions.
n
Checks the invocation state.
n
Extracts a value from the result.
n
Checks the RemotePSObject type.
var sess = host.openSession()
sess.addCommandFromString("dir " + directory)
var invResult = sess.invokePipeline();
//Show result
System.log( invResult.getHostOutput() );
Chapter 20 Using the PowerShell Plug-In
VMware, Inc. 125