Created
February 7, 2018 15:59
-
-
Save peterhynes/8661604255f8a235f8a05e29d481b7db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Python script to test connection to vcenter api and pull vm information | |
| from pyVim.connect import SmartConnect, Disconnect | |
| import ssl | |
| username = input("Please enter your username: ") | |
| password = input("Please enter your password: ") | |
| s =ssl.SSLContext(ssl.PROTOCOL_TLSv1_1) | |
| s.verify_mode = ssl.CERT_NONE | |
| try: | |
| c = SmartConnect(host="VcenterIP", user=username, pwd=password) | |
| print("Valid Certificate") | |
| except: | |
| c = SmartConnect(host="VcenterIP", user=username, pwd=password, sslContext=s) | |
| print("Invalid or Untrusted Certificate") | |
| print("") | |
| datacenter = c.content.rootFolder.childEntity[0] | |
| vms = datacenter.vmFolder.childEntity | |
| for i in vms: | |
| print("Virtual Machine Name: "+i.name) | |
| if i.guest is not None and i.guest.guestFullName is not None: | |
| print("Virtual Machine OS : "+i.guest.guestFullName) | |
| else: | |
| print("Virtual Machine OS : ") | |
| print("") | |
| Disconnect(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment