Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I choose Powershell over WMI to develop management interfaces?

We are discussing development of an improved management infrastructure for our distributed system. We use COM, web services and .NET components. Since we're based on Microsoft Windows Server XP/2003, I guess, we basically have two options:

  1. Powershell cmdlets
  2. WMI classes using System.Management and WMI providers for native code (class, instance, method, event)

Why would we choose Powershell over WMI?

like image 339
user33675 Avatar asked Nov 03 '08 15:11

user33675


People also ask

What is PowerShell WMI?

Windows Management Instrumentation (WMI) is a subsystem of PowerShell that gives admins access to powerful system monitoring tools. Though this system has been designed to allow for fast, efficient system administration, it also has a spookier side: it can be abused by insiders as a tool to surveil other employees.

Should I use CIM or WMI?

Microsoft has since deprecated the WMI commands in Windows in favor of their CIM counterparts. For example, if you are using PowerShell for management, you should use the CIM cmdlets and not the WMI cmdlets.

What is the main drawback of using the old remoting method of WMI?

The big drawback to the WMI cmdlets is that they use DCOM to access remote machines. DCOM isn't firewall friendly, can be blocked by networking equipment, and gives some arcane errors when things go wrong.

What is CIM in PowerShell?

CIM: Common Information Model (CIM) is the DMTF standard [DSP0004] for describing the structure and behavior of managed resources such as storage, network, or software components. WMI: Windows Management Instrumentation (WMI) is a CIM server that implements the CIM standard on Windows.


2 Answers

I would choose PowerShell over WMI for the following reasons:

  1. Writing a cmdlet is only adding a .NET Class.
  2. The PowerShell runtime provides command line parsing built in.
  3. Writing your management interface in PowerShell allows administrators the ability to integrate management of your application with that of other applications and services (like Exchange, Active Directory, or SQL Server).
  4. The PowerShell environment makes the pipeline available to administrators, enabling management tasks for your application to be done more efficiently.
  5. Discoverability. PowerShell, via Get-Command, Get-Member, and Get-Help, provides an extremely discoverable environment for admins to work in, resulting in a shorter learning curve to maintaining your application.

Even if you go the WMI route, PowerShell does have support for working with WMI (though there are a few glitches).

To me, PowerShell is the best way to surface a task oriented interface to an application. With the support Microsoft has been providing PowerShell, it is and will be a consistent interface to managing applications and services throughout the enterprise.

My day job is as an admin and I'm pushing all the vendors I work with towards surfacing a PowerShell management API, as this makes the learning curve and context switching for managing applications much lower. On the development side, I have written (and am still working on) a series of PowerShell cmdlets for one open source product I work with and am working on another set for a separate application.

like image 94
Steven Murawski Avatar answered Nov 15 '22 23:11

Steven Murawski


Jeffrey Snover answers the "why PowerShell" here. The post is in the context of SQL, but very much applicable here.

like image 20
halr9000 Avatar answered Nov 16 '22 00:11

halr9000