Site icon AI-Powered ITSM & Device Management

Powershell vs WMI for windows management and automation

Powershell vs WMI for windows management and automation

 

WMI (Windows Management Instrumentation) is the technique for querying and changing basic information about any windows server, including SQL Server or Exchange Server. It provides logical representation and structure of systems and services hosted on the server. Some of the examples of tasks you can do with WMI –

WMI is complicated

However with time and features WMI has become slightly difficult to use. Powershell tries to solve few of the problems. Powershell 2.0 supports registry, processes, services, event logs etc. Powershell 3.0 with windows 8 and server 2012, introduced hardware inventory access as storage and network adapters.

Powershell is easy

Windows powershell used Get-WmiObject which simplified WMI. It saves minimum of 7 lines/vbscripts/perl script as compared to WMI. The single-line commands in powershell are also called cmdlets. The underlying technology of Powershell is still WMI, but the classes are basically wrapped and exposed as functions that behave like Windows PowerShell cmdlets

Powershell can access below modules –
Sample commands in WMI vs Powershell –
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, volumeserialnumber -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, reespace, 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”}

Advantages of Powershell

With Anakage intelligent training technology it is easier to learn these concepts . It guides you step by step on your system. Above topic being discussed is also part of our “Learning Application” for Windows Active Directory. If you want to evaluate it let us know by sending a mail to us at enterprise@anakage.in . You can know more about our offering for training.

 

Exit mobile version