def connect(hostname): ''' Establishes a WMI connection to a windows Hyper-V Host ''' conn = wmi.connect_server(server=hostname, user=env['wmi_user'], password=env['wmi_pass'], namespace=r"root\virtualization\v2") client = wmi.WMI(wmi=conn) return (client)
def connectTo(cls, server, user="", password="", impersonation_level="Impersonate", namespace=""): """ Connect to a remote server connectTo(server, [user], [password], [impersonation_level], [namespace]) --> COMObject Instance """ print "Connecting to '%s'" % server if user == "": # asking for missing login username user = raw_input("Username: "******"": # asking for missing login password password = getpass.getpass() connect = wmi.connect_server(server=server, user=user, password=password, impersonation_level=impersonation_level, namespace=namespace) return connect
def connect_as(c): connection = wmi.connect_server ( server="other_machine", user="******", password="******" ) c = wmi.WMI (wmi=connection) # # Using wmi module at least 1.0rc3 # c = wmi.WMI ( computer="other_machine", user="******", password="******" )
def wmi_instance(computer, user, password): try: # # Using wmi module before 1.0rc3 # connection = wmi.connect_server(server=computer, user=user, password=password) instance = wmi.WMI(wmi=connection) return instance except Exception as ex: del ex # # Using wmi module at least 1.0rc3 # instance = wmi.WMI(computer=computer, user=user, password=password) return instance
def get_wmi_instance(computer, user, password): try: # # Using wmi module before 1.0rc3 # connection = wmi.connect_server(server=computer, user=user, password=password) instance = wmi.WMI(wmi=connection) return instance except Exception: # # Using wmi module at least 1.0rc3 # instance = wmi.WMI(computer=computer, user=user, password=password) return instance
def check(self, instance): Host, UserName, PassWord = self.get_config(instance) try: connection = wmi.connect_server(server=Host, namespace=self.NAMESAPCE, user=UserName, password=PassWord) conn = wmi.WMI(wmi=connection) except Exception as e: self.log.exception(e) sys.exit() self.conn = conn self.get_computer_imformation() self.get_cpu_imformation() self.get_memory_information() self.get_disk_imformation()
def infohardlocal(): print('Info HW Local:\n\n') nombreequipo = platform.node() conexion = wmi.connect_server(nombreequipo) c = wmi.WMI(wmi=conexion) proce = 'Procesador: ' + str(c.Win32_Processor()[0].Name) memram = 'Memoria RAM Total: ' + str( round( int(c.Win32_ComputerSystem()[0].TotalPhysicalMemory) / 1073741824)) + ' GB\n\n' for hd in range(len(c.Win32_LogicalDisk())): if str(c.Win32_LogicalDisk()[hd].Description) == 'Disco fijo local': letrahdd = 'HDD ' + str(hd + 1) + ' - Letra asignada: ' + ( c.Win32_LogicalDisk()[hd].DeviceID) hddtotal = str( round( int(c.Win32_LogicalDisk()[hd].Size) / 1073741824)) + ' GB' hdd = letrahdd + '. TamaƱo Total: ' + hddtotal print(hdd) print(proce) print(memram)
import wmi # c = wmi.WMI("osg-appdf.segurosorion.local", user="******", password="******") connection = wmi.connect_server(server="osg-appdf.segurosorion.local", user="******", password="******") c = wmi.WMI(wmi=connection) for os in c.Win32_OperatingSystem(): print os.Caption
def __init__(self, server_name): connection = wmi.connect_server(server=server_name, namespace=r"root\virtualization") self.conn = wmi.WMI(wmi=connection) self.management = self.conn.Msvm_VirtualSystemManagementService()[0] self.switch_svc = self.conn.Msvm_VirtualSwitchManagementService()[0]
# Creation first line into the file to create all field file.write("Date/Time;Hostname;OS;Installation Date;Last reboot;Architecture;Domaine/Workgroup;Manufacturer;Model;Serial;TotalPhysicalMemory;ProcessorType;MaxClockspeed (Mhz);NumberOfCores;NumberOfLogicalProcessors;DiskName;TotalVolSize;TotalVolfreespace;InstalledSoftwares" + "\n") # create try/catch functionalities to continue if an error occur (for example if some computers are unreachable) try: # Create IP address range net4 = ipaddress.ip_network('10.0.1.0/30') # Discovering all IP address based with current range for x in net4.hosts(): print(x) # WMI functionalities to connect remotely on each computers included within ip range connection = wmi.connect_server(server=x, user=user, password=password) wmiObject = wmi.WMI(wmi=connection) # Insert new line file.write("\n") # Insert Inventory date in output file now = datetime.now() file.write(now.strftime("%x") + " " + now.strftime("%X") + ";") # Retrieve some system inventory informations on servers via WMI (eg.: Computername, OS version, Install date...) for OS in wmiObject.win32_OperatingSystem(): file.write(OS.CSName + ";" + OS.Caption + ";" + OS.InstallDate + ";" + OS.LastBootUpTime + ";" + OS.OSArchitecture + ";") # Retrieve some system inventory informations on servers via WMI (eg.: Domain/Workgroup, Manufacturer, Model...)
import wmi # # Using wmi module before 1.0rc3 # connection = wmi.connect_server ( server="other_machine", user="******", password="******" ) c = wmi.WMI (wmi=connection) # # Using wmi module at least 1.0rc3 # c = wmi.WMI ( computer="other_machine", user="******", password="******" )
def __init__(self, server_name): connection = wmi.connect_server(server=server_name, namespace=r"root\virtualization\v2") self.conn = wmi.WMI(wmi=connection) self.management = self.conn.Msvm_VirtualSystemManagementService()[0]
if args.ip is None and args.user is None and args.password is None: try: c = wmi.WMI("localhost") except wmi.x_wmi, x: print x.com_error elif args.ip is not None and args.user is None and args.password is None: try: c = wmi.WMI(args.ip) except wmi.x_wmi, x: print x.com_error sys.exit(-1) else: try: connection = wmi.connect_server(server=args.ip, user=args.user, password=args.password) c = wmi.WMI(wmi=connection) except Exception, e: print e sys.exit(-1) print "-= Operating System Information =-" for os in c.Win32_OperatingSystem(): print "Name:", os.name print "CName:", os.csname print "Manufacturer:", os.Manufacturer print "Build Number:", os.buildnumber print "Boot Device:", os.bootdevice print "Version:", os.version print "Win Directory:", os.windowsdirectory
def get_wmi_client(self, server, user, password): conn = wmi.connect_server(server=server, user=user, password=password) client = wmi.WMI(wmi=conn) return client
def __connect(self): connection = wmi.connect_server(server=self.server, user=self.user, password=self.password) instance = wmi.WMI(wmi=connection) return instance
def register_physical(self): connection = wmi.connect_server(server=self.server, user=self.user, password=self.password) self.physical_connection = wmi.WMI(wmi=connection)
def register_virtual(self): connection = wmi.connect_server(server=self.server, user=self.user, password=self.password, namespace="root\\virtualization\\v2") self.virtual_connection = wmi.WMI(wmi=connection)
# -*- coding:utf-8 -*- import wmi conn = wmi.connect_server(server="192.168.0.100", user="******", password="******", namespace=r"root\virtualization\v2") client = wmi.WMI(wmi=conn) objs = client.query("Select * from Msvm_ConcreteComponent") #OK for obj in objs: print(obj) # PS D:\vscode> & C:/Python38/python.exe d:/vscode/python/hyperv/Msvm/get_concrete_component.py # instance of Msvm_ConcreteComponent # { # GroupComponent = "\\\\WIN-667A0LKMU6R\\root\\virtualization\\v2:Msvm_Memory.CreationClassName=\"Msvm_Memory\",DeviceID=\"Microsoft:4764334E-E001-4176-82EE-5594EC9B530E\\\\Aggregate\",SystemCreationClassName=\"Msvm_ComputerSystem\",SystemName=\"WIN-667A0LKMU6R\""; # PartComponent = "\\\\WIN-667A0LKMU6R\\root\\virtualization\\v2:Msvm_Memory.CreationClassName=\"Msvm_Memory\",DeviceID=\"Microsoft:4764334E-E001-4176-82EE-5594EC9B530E\\\\0\",SystemCreationClassName=\"Msvm_ComputerSystem\",SystemName=\"WIN-667A0LKMU6R\""; # }; # instance of Msvm_ConcreteComponent # { # GroupComponent = "\\\\WIN-667A0LKMU6R\\root\\virtualization\\v2:Msvm_Memory.CreationClassName=\"Msvm_Memory\",DeviceID=\"Microsoft:4764334E-E001-4176-82EE-5594EC9B530E\\\\Aggregate\",SystemCreationClassName=\"Msvm_ComputerSystem\",SystemName=\"WIN-667A0LKMU6R\""; # PartComponent = "\\\\WIN-667A0LKMU6R\\root\\virtualization\\v2:Msvm_Memory.CreationClassName=\"Msvm_Memory\",DeviceID=\"Microsoft:4764334E-E001-4176-82EE-5594EC9B530E\\\\1\",SystemCreationClassName=\"Msvm_ComputerSystem\",SystemName=\"WIN-667A0LKMU6R\""; # }; # instance of Msvm_ConcreteComponent # { # GroupComponent = "\\\\WIN-667A0LKMU6R\\root\\virtualization\\v2:Msvm_ResourcePool.InstanceID=\"Microsoft:353B3BE8-310C-4cf4-839E-4E1B14616136\""; # PartComponent = "\\\\WIN-667A0LKMU6R\\root\\virtualization\\v2:Msvm_DiskDrive.CreationClassName=\"Msvm_DiskDrive\",DeviceID=\"Microsoft:353B3BE8-310C-4cf4-839E-4E1B14616136\\\\3\",SystemCreationClassName=\"Msvm_ComputerSystem\",SystemName=\"WIN-667A0LKMU6R\"";
import wmi connection = wmi.connect_server ( server="vlw189.eng.rtca", user="******", password="******" ) c = wmi.WMI(wmi=connection) for opsys in c.Win32_OperatingSystem (): print opsys systemArch = c.Win32_Processor.Caprion print systemArch #for tpc in c.Win32_Processor(): # print tpc #result = c.Win32_Product.Install( # #PackageLocation="\\\\mypc\\tmp\\python-3.4.1.msi", # PackageLocation="\\\\jaffar32\\installation_bin\\puppet-windows\\puppetdeploy.vbs", # AllUsers=True #) #print( result)
__author__ = 'Administrator' import wmi connection = wmi.connect_server(server='172.168.10.242', user='******', password='******') WMI = wmi.GetObject('winmgmts:') # sql1 = 'SELECT DiskReadsPerSec,DiskWritesPerSec FROM Win32_PerfRawData_PerfDisk_PhysicalDisk WHERE Name="_Total"' # result = WMI.ExecQuery(sql1)