python - List stored in variable converted to dictionaries -
i using following perform wmi query on windows endpoint returns results in list. want convert list dictionary key:value can search keys "name" name return: "aspnet" "guest" "admin".
import wmi_client_wrapper wmi wmic = wmi.wmiclientwrapper( username="corp.testdomain.com/administrator", password="fakepassword", host="192.168.1.100", ) output = wmic.query("select * win32_useraccount localaccount = true") {'status': 'ok', 'domain': 'localhost', 'description': 'account used running asp.net worker process (aspnet_wp.exe )', 'installdate': none, 'caption': 'localhost\\aspnet', 'disabled': false, 'passwordchangeable': false, 'lockout': false, 'accounttype': '512', 'sid': '45474748484848-1002', 'localaccount': true, 'fullname': 'asp.net ma chine account', 'sidtype': '1', 'passwordrequired': false, 'passwordexpires': false, 'name': 'aspnet'} {'status': 'degraded', 'domain': 'localhost', 'description': 'built-in account guest access computer/domain', ' installdate': none, 'caption': 'localhost\\guest', 'disabled': true, 'passwordchangeable': false, 'lockout': false, 'accou nttype': '512', 'sid': '3645747474747858-501', 'localaccount': true, 'fullname': '', 'sidtype': '1', 'passwordrequired': false, 'passwordexpires': false, 'name': 'guest'} {'status': 'ok', 'domain': 'localhost', 'description': 'built-in account administering computer/domain', 'installd ate': none, 'caption': 'localhost\\sol2112', 'disabled': false, 'passwordchangeable': true, 'lockout': false, 'accounttype ': '512', 'sid': '834668384636846843-500, 'localaccount': true, 'fullname': '', 'sidtype': '1', 'pass wordrequired': true, 'passwordexpires': false, 'name': 'admin'}
you can
>>> dict1 = {'status': 'ok', 'domain': 'localhost', 'description': 'account used running asp.net worker process (aspnet_wp.exe )', 'installdate': none, 'caption': 'localhost\\aspnet', 'disabled': false, 'passwordchangeable': false, 'lockout': false, 'accounttype': '512', 'sid': '45474748484848-1002', 'localaccount': true, 'fullname': 'asp.net ma chine account', 'sidtype': '1', 'passwordrequired': false, 'passwordexpires': false, 'name': 'aspnet'} >>> print dict1['name'] aspnet
Comments
Post a Comment