#!/usr/bin/env python # coding: utf-8 # # GetInstance # <--- Back # The [`GetInstance()`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.WBEMConnection.GetInstance) method returns a [`pywbem.CIMInstance`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstance) object, given a [`pywbem.CIMInstanceName`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstanceName) object that references the desired CIM instance. # # The following code extends the [EnumerateInstanceNames](https://nbviewer.jupyter.org/github/pywbem/pywbem/blob/master/docs/notebooks/enuminstnames.ipynb) example by the use of `GetInstance` on each of the returned instance paths. # In[ ]: from __future__ import print_function import sys import pywbem username = 'user' password = 'password' classname = 'CIM_ComputerSystem' namespace = 'root/cimv2' server = 'http://localhost' conn = pywbem.WBEMConnection(server, (username, password), default_namespace=namespace, no_verification=True) try: cs_paths = conn.EnumerateInstanceNames(classname, namespace) except pywbem.Error as exc: print('EnumerateInstanceNames failed: %s' % exc) sys.exit(1) for cs_path in cs_paths: print('Instance at: %s' % cs_path) try: cs_inst = conn.GetInstance(cs_path) except pywbem.Error as exc: print('GetInstance failed: %s' % exc) sys.exit(1) for prop_name, prop_value in cs_inst.items(): print(' %s: %r' % (prop_name, prop_value)) # <--- Back