Sample Exchange

 View Only

Returns names of objects found on a vSphere environment 

Aug 19, 2015 11:36 PM

This sample code shows how to make a connection to ESX or vCenter, and get back some simple information from it.

How to Run

In order to run this sample code you must provide four arguments:
[1] The server name or IP address
[2] The user name to log in as
[3] The password to use
[4] The type of object to look for

You will need to get the vim25.jar library from the VMware vSphere JDK. It is in the VMware-vSphere-SDK-5.5.0\vsphere-ws\java\JAXWS\lib directory.

You can run this sample code with a command similar to the following:
java -cp "vim25.jar" com.vmware.sample.ListObjects <ip-or-domain-name> <user> <password> <type>
For example:
java -cp "vim25.jar" com.vmware.sample.ListObjects 127.0.0.1 root rootPassword VirtualMachine
java -cp "vim25.jar" com.vmware.sample.ListObjects 127.0.0.1 root rootPassword HostSystem

The 127.0.0.1 address is the local host, so will work if you are running the script from the same machine as vCenter is installed on.  If not, put in the vCenter machine's IP or domain name. If you password contains strange characters that your shell uses (such as ! # ; | and so on), you should put quotes around it.

Output

You will see the output similar to the following when you run the sample:
name = vm1a


#Apache2.0
#Objects
#vSphereManagementSDK
#list
#Java

Statistics
0 Favorited
0 Views
1 Files
0 Shares
1 Downloads
Attachment(s)
zip file
Returns-names-of-objects-found-on-a-vSphere-environment-m....zip   21 KB   1 version
Uploaded - Apr 09, 2024

Tags and Keywords

Related Entries and Links

No Related Resource entered.