Wmic
Aller à la navigation
Aller à la recherche
| Fiche express | |
|---|---|
| Domaine | Interrogation et administration WMI |
| Commande | wmic
|
| Contexte | Client WMI en ligne de commande (Windows et Linux) |
| Voir aussi | WMI · WBEMCLI · Perfmon |
wmic (Windows Management Instrumentation Command-line) interroge et pilote WMI en ligne
de commande, en utilisant le langage WQL. Un client équivalent existe sous Linux
(paquet wmi-client).
Syntaxe de base (Windows)
wmic CPU get Datawidth,Description
wmic /NODE:serveur CPU GET NumberOfCores, NumberOfLogicalProcessors
wmic /? :: liste des alias
wmic csproduct get name, identifyingnumber :: numero de serie de la machine
Gestion des processus
wmic PROCESS CALL CREATE calc.exe
wmic PROCESS where (Name="notepad.exe") DELETE
wmic PROCESS where Name="calc.exe" CALL TERMINATE
wmic process where (name like "chrome%") get handle /format:list
Filtrer par charge CPU :
wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 50) get Name, IDProcess, PercentProcessorTime /format:list
Modes CLASS / PATH
wmic CLASS Win32_Process GET Name, Handle, PageFaults
wmic PATH Win32_Process.Description="explorer.exe"
CLASS accède directement aux classes du schéma WMI, PATH aux instances,
en sortant du mode « alias » par défaut.
Exports HTML
wmic /output:c:\services.htm service where started=true get /format:hform
wmic /output:c:\reseau.htm nicconfig where ipenabled=true get /format:hform
wmic product list full /format:hform.xsl > c:\programmes.htm
Administration à distance
wmic OS WHERE Primary=TRUE CALL Reboot
wmic product where name="NomProgramme" call uninstall
wmic /node:"NomPC" /user:"identifiant" /password:"motdepasse" product where name="NomProgramme" call uninstall
Paramétrer la carte réseau :
wmic NICConfig where ipenabled=true CALL EnableStatic 192.168.1.61,255.255.255.0
wmic NICConfig where ipenabled=true CALL SetGateways 192.168.1.1
wmic NICConfig where ipenabled=true CALL SetDNSServerSearchOrder 192.168.1.1
wmic NICConfig where ipenabled=true get MACAddress /value
Joindre un domaine :
wmic ComputerSystem WHERE name!=NULL CALL JoinDomainOrWorkgroup "", 3, "exemple.local", "MotDePasse", "EXEMPLE\Administrateur"
Client wmic sous Linux
apt-get install wmi-client
Syntaxe générale (le résultat peut être filtré avec Grep / Sed) :
wmic -U DOMAINE/utilisateurAdmin%motdepasse //HOTE "requete_WQL"
wmic -U Administrateur%motdepasse //10.140.10.10 "SELECT * FROM Win32_ComputerSystem"
Requêtes WQL utiles
-- Utilisateur connecté
SELECT UserName FROM Win32_ComputerSystem
-- État des services
SELECT State FROM Win32_Service
SELECT Name,State,StartMode FROM Win32_Service WHERE StartMode="Auto"
-- Mémoire disponible / physique
SELECT AvailableBytes FROM Win32_PerfRawData_PerfOS_Memory
SELECT Capacity FROM Win32_PhysicalMemory
-- Espace disque (MediaType=12 : disques durs)
SELECT FreeSpace, Size FROM Win32_LogicalDisk WHERE MediaType = '12'
-- Charge CPU par processeur
SELECT LoadPercentage FROM Win32_Processor
-- File d'attente disque (>2 = probleme)
SELECT Name,CurrentDiskQueueLength FROM Win32_PerfFormattedData_PerfDisk_PhysicalDisk
-- Utilisation du fichier d'echange
SELECT AllocatedBaseSize,CurrentUsage FROM Win32_PageFileUsage
-- Uptime (<3600 = reboot dans l'heure)
SELECT SystemUpTime FROM Win32_PerfFormattedData_PerfOS_System
Supervision Nagios
Le plugin check_wmi_plus (Perl) s'appuie sur le client wmic Linux pour
superviser des hôtes Windows sans agent. Il se déploie dans libexec et se configure
via check_wmi_plus.conf.
Voir aussi
- WMI — présentation générale
- WBEMCLI — client WBEM alternatif sous Linux
- Get-wmiobject — équivalent PowerShell