Compartilhar via


wmic vs WMI Powershell cmdlets

Compare WMIC.EXE with Windows Powershell Cmdlets for WMI

The WMI command-line (WMIC) utility provides a command-line interface for WMI. With Windows 7 you can do everything that you can do with wmic using Windows Powershell and much more by leveraging powerful features of Windows Powershell.

Below are some scenarios in wmic and their equivalent in Windows Powershell commands, try them out and compare the results and general experience working with both -

WMIC Version

Windows Powershell Version

wmic bios get caption, manufacturer, smbiosbiosversion, version

get-wmiobject win32_bios caption, manufacturer, smbiosbiosversion, version

wmic logicaldisk where drivetype=3 get name, freespace, systemname, filesystem, size, volumeserialnumber /format:list

get-wmiobject win32_logicaldisk name, freespace, systemname, filesystem, size, volumeserialnu

mber -filter drivetype=3

wmic process call create 'notepad.exe'

invoke-wmimethod win32_process -name create -argumentlist 'notepad.exe'

wmic /node:<machine name> /user:<username>/password:<password> logicaldisk where drivetype=3 get name, freespace, filesystem, size

Get-wmiobject -ComputerName <machine name> -credential <remote credentials> win32_logicaldisk name, freespace, systemname, filesystem, size, volumeserialnumber -filter drivetype=3

WMIC PROCESS where name='notepad.exe' delete

gwmi win32_process -filter "name='notepad.exe'" | remove-wmiobject

wmic ENVIRONMENT SET NAME="TEMP", VARIABLEVALUE="NEW" , username="<system>"

gwmi win32_environment -filter 'Name="testvar" and username="<system>"' | set-wmiinstance -argument @{variableValue="testvalue"}

This post talks about some other reasons why using powershell is a good idea if you are working with WMI

 

Kapil Mathur [MSFT]

Comments

  • Anonymous
    January 20, 2010
    yea wmic is really cool and I'm always amazed when I tell an SA to just use wmic and they've never heard about it!  Put alas gwmi is killer too!

  • Anonymous
    January 27, 2010
    Kool :)

  • Anonymous
    October 23, 2014
    I have a powershell script that runs this command to delete a printer.  It works and the printer is deleted, but it also hangs the powershell script.  How can I run this command without having it hang on me. wmic printer where "Name LIKE '$printName'" delete

  • Anonymous
    April 15, 2015
    Z.K. I know this is old but you could just use printui /dl /n "$prinName

  • Anonymous
    April 15, 2015
    ZK I know this is old but you could just use printui /dl /n "$prinName