Skip to main content

WMIC

WMIC is a command line interface to WMI (Windows Management Instrumentation). WMI is a powerful management interface that we can access from directly from command line. 

WMIC can be used to manage remote computers. 
If we want to execute WMIC commands on a single computer we prepend command with /node: as shown below:

/node:hostname123 - specifies single server 
(wmic /node:hostname123 qfe where hotfixid="KB974571" list full)

If we want to execute WMIC commands on multiple computers listed in c:\nodes.txt we prepend command with /node:@ as shown below:


/node:@'c:\node.txt' - specifies text file with server names 
 (wmic /node:@'c:\node.txt' qfe where hotfixid="KB974571" list full)

It's worth keeping in mind that not all WMI classes have corresponding classes (called aliases) in WMIC. It is however possible to access WMI classes directly from WMIC:

wmic /namespace:\\root\NAMSPACE path CLASSNAME

To directly access WMI classes in CIMv2 namespace  

wmic /namespace:\\root\cimv2 path win32_useraccount


To see if there are any predictive failures using WMIC: 

wmic /namespace:\\root\wmi PATH MSStorageDriver_FailurePredictStatus get 

We can use Microsoft WMI Studio to explorer WMI classes, properties and methods


We can tell WMIC to repeat a command at specified interval:

/every:5    -  repeats a command every 5 seconds 

WMIC can also output to an HTML file using /output and /format switches 

wmic /output:c:\cpu.htm cpu get name, maxclockspeed /format:hform.xsl

HTML output is no longer available in Windows 2008 or 7, on these platforms we omit /format switch.




qfe - wmic query for hotfixes and patches 

query for a given patch by using a KB ID: 

wmic qfe where hotfixid="KB974571" list full


process - process management 

query for an exe path of a process 

wmic process where caption="Apntex.exe" get executablepath  

query for a process's thread count  

wmic process where caption="Apntex.exe" get threadcount 

to execute a  command on a remote machine  

wmic /node:hostname process call create 'cmd.exe /c net stop iisadmin' 

To kill a process using WMIC: 

wmic process where caption="notepad.exe" call terminate 


service - service management: 

Disable service using WMIC

wmic service where caption='SSDP Discovery Service' call changestartmode disabled 

Enable service using WMIC

wmic service where caption='SSDP Discovery Service'  call changestartmode enabled 

Stop service using WMIC

wmic service where caption='SSDP Discovery Service'  call stopservice 

Startservice using WMIC

wmic service where caption='SSDP Discovery Service' call startservice 

Retrieve service status

wmic service where name='........'  get status 

To retrieve service name: 

wmic service list instance 


product - Software Management 

List installed software: 

wmic product get

wmic product list brief 
  
Only required attributes: 

wmic product get name, vendor, version 

Only products from Adobe: 

wmic product where "vendor like 'adobe%'" get 

  
 Find out a username of a user logged on to a computer: 

wmic /NODE:hostname COMPUTERSYSTEM GET USERNAME 

 Configure a static IP address using WMIC: 

wmic nicconfig where Index=1 call EnableStatic ("10.10.10.10"), ("255.255.255.0") 

To retrieve index ID: 

wmi nicconfig where ipenabled='true' 
  
Enable DHCP using WMIC: 

wmic nicconfig where Index=1 call EnableDHCP


File management using WMIC: 

list details about c:\script\comps.txt file 

wmic datafile where "path='\\scripts\\' and name='c:\\scripts\\comps.txt'" list full   

Backup event log using WMIC:

wmic nteventlog where "logfilename='system'" call backupeventlog "c:\system.evt"

wmic nteventlog where "logfilename='application'" call backupeventlog "c:\application.evt"


Query local groups:

wmic group where (localaccount=true) get name

Local groups with "sql" in the name:


wmic group where (localaccount=true and name like 'sql%') get name

Comments

Popular posts from this blog

x.509 Certificates - Critical vs non-critical extensions

Extensions are used to associate additional information with the user or the key.  Each certificate extension has three attributes - extnID, critical, extnValue extnID - Extension ID - an OID that specifies the format and definitions of the extension critical - Critical flag - Boolean value extnValue - Extension value  Criticality flag specifies whether the information in an extension is important. If an application doesn't recognize the extension marked as critical, the certificate cannot be accepted. If an extension is not marked as critical (critical value False) it can be ignored by an application. In Windows, critical extensions are marked with a yellow exclamation mark,  View certificate extensions using OpenSSL: # openssl x509 -inform pem -in cert.pem -text -noout (output abbreviated)         X509v3 extensions:             X509v3 Key Usage: critical                 Digital Signature, Key Encipherment             X509v3 Subject Key Identifier

Cisco ASA Certificate Revocation Checking

ASA supports status verification using CRLs and OCSP. CRL can be retrieved using HTTP, LDAP or SCEP. Revocation checking using CRL: Over HTTP: ciscoasa(config)# crypto ca trustpoint ASDM_TrustPoint2 ciscoasa(config-ca-trustpoint)# revocation-check crl ciscoasa(config-ca-crl)# protocol http By default ASA will use address listed in CDP extension of the certificate that is being validated.  To override default behaviour we need to add the following in the CRL configuration context. ciscoasa(config-ca-crl)# policy static ciscoasa(config-ca-crl)# url 1 http://cdpurl.kp.local/crl.crl Over LDAP: Certificate I'm using for this lab, doesn't have LDAP address in its CDP extension. Therefore I'm using "policy static"  to specify LDAP URL where CRL can be retrieved.  ciscoasa(config)# crypto ca trustpoint ASDM_TrustPoint2 ciscoasa(config-ca-trustpoint)# revocation-check crl ciscoasa(config-ca-trustpoint)# crl configure ciscoasa

Count number of lines - 'findstr'

How do I count number of lines in a command output? findstr /r/n "^" | find /c ":" Above commands will display number of lines output by whatever command (well, nearly whatever) you specify in the front.  For example:  C:\>ping localhost | findstr /r/n "^" | find /c ":" FINDSTR: // ignored 12 This comes handy if you want to find out how many OUs you have in Active Directory: dsquery ou  -limit 0 | findstr /r/n "^" | find /c ":" How many user accounts there are: dsquery user -limit 0 | findstr /r/n "^" | find /c ":" Computers: dsquery computer -limit | findstr /r/n "^" | find /c ":"