Powershell vs WMI for windows management and automation

Powershell

 

Powershell

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 –

  • Working with the registry
  • Working with processes
  • Working with services
  • Performing hardware inventory
  • Working with files and folders
  • Working with event logs

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 –

  • WMI– Windows Management Instrumentation. It is the Microsoft implementation of Web-Based Enterprise Management (WBEM) allowing access to data. WMI uses the Common Information Model (CIM) to describe objects such as systems, applications, network equipment.
  • CIM– Common Information Model. It is a set of standards that describes how information is structured and represented at the heart of the system. It was created by the DMTF (Distributed Management Task Force), a working group to which Microsoft belongs.
  • PSWA– PowerShell Web Access. This new function allows secure access to a Windows PowerShell console from a browser so as to interact with any system, even if it is outside the domain.

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

  • Powershell has access to all .NET libraries in addition to items mentioned above so you can take advantage of anything you could with a language like C# or VB.NET.
  • Powershell often allows you to do more with less compared to VBscript. In some cases you can reduce VBscripts that are hundreds of lines to just tens of lines in PowerShell.
  • Microsoft has designed powershell for the OS and application automation across all its platforms.
  • PowerShell is also interactive. This allows to try out things at the console first and integrate them into larger more complicated scripts.

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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *