PowerShell for Windows Admins

January 12, 2012  3:25 PM

Friday 13th

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tomorrow is Friday 13th and Manning are offering $13 off any purchase at manning.com.

This would be a good time to get a copy of PowerShell in Practice or PowerShell and WMI

use code “fri1312” at checkout

January 9, 2012  2:15 PM

CIM instances

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We are use to using Get-WmiObject to retrieve information from WMI. if you have been following this blog for any length of time you will have see lots of examples of that particular cmdlet. The CIM equivalent is Get-CIMInstance. It might appear that Get-CIMClass would be used but that is used to get information about the WMI class itself. think Get-WmiObject –List  on steroids.

This should be familiar

Get-WmiObject -Class Win32_ComputerSystem

The direct comparison is

Get-CimInstance -ClassName Win32_ComputerSystem


We can run WQL queries

$q = "SELECT * FROM Win32_ComputerSystem"
Get-WmiObject -Query $q


Get-CimInstance -Query $q


And we can filter

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3"

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3"


Another difference is that CIM cmdlets tend to default to a table output but WMI cmdlets tend to default to a list


We can even select properties

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -Property DeviceID, FreeSpace, Size

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" -SelectProperties DeviceID, FreeSpace, Size


Here we get a big difference

WMI returns the properties we asked for plus the System properties (those starting with __) for the class. CIM returns the whole object but only the select properties and the system type properties are populated.


So far you could be forgiven for thinking these are very similar and we don’t need both. The big differences come when we look at access remote machines next time.

January 6, 2012  2:39 PM


Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Do you know the difference between WMI and CIM?

CIM is the Common Information Model – http://www.dmtf.org/standards/cim

“CIM provides a common definition of management information for systems, networks, applications and services, and allows for vendor extensions. CIM’s common definitions enable vendors to exchange semantically rich management information between systems throughout the network.”


WMI is Microsoft’s implementation of CIM

Get-WmiObject CIM_DiskDrive
Get-WmiObject Win32_DiskDrive

return the same information

Win32_DiskDrive is derived from CIM_DiskDrive.  The CIM class is the superclass for the Win32 class.

Why is this important?

Because in PowerShell v3 Microsoft introduce a while new API for working with WMI -  and whole new bunch of cmdlets


compare these to the WMI cmdlets


The analogous CIM cmdlets are highlighted.

The CIM cmdlets use different .NET classes to WMI cmdlets

PS> Get-WmiObject Win32_DiskDrive | gm

   TypeName: System.Management.ManagementObject#root\cimv2\Win32_DiskDrive


PS> Get-CimInstance Win32_DiskDrive | gm

   TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_DiskDrive


Microsoft have made a big investment in WMI/CIM for Windows 8.  I’ll explore some of the new things in coming posts

January 2, 2012  8:35 AM

UK PowerShell Group–January 2012

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

This is our five year anniversary meeting!!

So it seems fitting to look at PowerShell v3 and how we got to where we are now.

When: Tuesday, Jan 24, 2012 7:30 PM (GMT)

Where: Virtual


A look at whats new in PowerShell v3 and how we can incorporate it into our administration tasks


Richard Siddaway has invited you to attend an online meeting using Live Meeting.
Join the meeting.
Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
  2. Copy and paste the required information:
    Meeting ID: SHGTW9
    Entry Code: 3%8>`{p’K
    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.

January 1, 2012  7:50 AM

UK PowerShell Group – Q1 2012

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The first three meetings for 2012 are


27 March 2012             -  CIM cmdlets & cmdlets over objects 

28 February 2012        -  PowerShell and SQL Server


24 January 2012           -  PowerShell v3 overview


Details to follow

January 1, 2012  6:12 AM

Changing IP Connection Metric

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A question on the forums asked how the connection metrics could be set on a Windows system.

We need to start by identifying the network adapters using this function

function test-ipmetric {
Get-WmiObject -Class Win32_NetworkAdapter -Filter "AdapterType = ‘Ethernet 802.3’" |
foreach {
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=$($_.DeviceId)" |
select Description, Index, IPEnabled, IPConnectionMetric

test-ipmetric | ft -a

Description                                                                                  Index IPEnabled IPConnect
———–                                                                                      —–     ———    ———
NVIDIA nForce 10/100/1000 Mbps Networking Controller              7         True        20
Atheros AR5007 802.11b/g WiFi Adapter                                      11        True        10
Microsoft Virtual WiFi Miniport Adapter                                          17        False


I get three adapters returned

The important ones are those that have IPEnabled set to True.

identify which is to have priority then run

function set-ipmetric {
param (
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=$index" |
Invoke-WmiMethod -Name SetIPConnectionMetric -ArgumentList $metric

I used

set-ipmetric -index 7 -metric 200

set-ipmetric -index 11 -metric 100

This sets my wired to a higher metric than the wireless. If I wanted it the other way round

set-ipmetric -index 7 -metric 100

set-ipmetric -index 11 -metric 200

The system must be rebooted for the changes to take effect

December 23, 2011  1:34 PM

Selecting Property order

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

If you run

Get-WmiObject -Class Win32_ComputerSystem

you get a few properties displayed

Domain              : WORKGROUP
Manufacturer        : Hewlett-Packard
Model               : HP G60 Notebook PC
Name                : RSLAPTOP01
PrimaryOwnerName    : Richard
TotalPhysicalMemory : 2951139328


Now if you want all properties you need

Get-WmiObject -Class Win32_ComputerSystem | fl *


Get-WmiObject -Class Win32_ComputerSystem | select *

If you want a particular set of properties then this will work

Get-WmiObject -Class Win32_ComputerSystem | select Name, SystemType, Manufacturer, Model, BootupState


A comment was left on this post


regarding how the reader wanted a specific set of properties displayed first and then all of the other properties in any appropriate order

You might think that this would work

Get-WmiObject -Class Win32_ComputerSystem | select Name, SystemType, Manufacturer, Model, BootupState, *

but in fact we get a series of errors and then all of the properties in the standard order.

Select-Object has  –Property and –ExcludeProperty parameters but they won’t help us as we want to display all properties

One thing to remember is that you can do this

$p = "Name", "SystemType", "Manufacturer", "Model", "BootupState"
Get-WmiObject -Class Win32_ComputerSystem | select $p


Define the list of properties in an array and use that as the selection.  This because –Property is a positional property and takes position 1 so is assumed if no parameter name is supplied. What we are doing is this

$p = "Name", "SystemType", "Manufacturer", "Model", "BootupState"
Get-WmiObject -Class Win32_ComputerSystem | select -Property $p

This enables us to write a function that takes an object and list of properties as input and creates a selection list based on the object’s full property list. The properties defined to the function are selected first and then all other properties in the order that Get-Member supplies them.

function Select-Order {            
param (            
PROCESS {            
$proplist = $firstprop            
$Inputobject | Get-Member -MemberType Property |            
foreach {            
 if ($firstprop -notcontains $_.Name){            
   $proplist += $_.Name            
$InputObject | select -Property $proplist            


You can use it like this

$p = "Name", "SystemType", "Manufacturer", "Model", "BootupState"

Get-WmiObject Win32_ComputerSystem | Select-Order -firstprop $p


Get-WmiObject Win32_ComputerSystem | Select-Order -firstprop "Name", "SystemType", "Manufacturer", "Model", "BootupState"


$o = Get-WmiObject Win32_ComputerSystem                                   
Select-Order -InputObject $o -firstprop $p 


Select-Order -InputObject $o -firstprop "Name", "SystemType", "Manufacturer", "Model", "BootupState"

December 23, 2011  7:48 AM

PowerShell workflows

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Just as remoting was viewed as the biggest gain in PowerShell v2 it looks like PowerShell workflows will be one of the biggest features on PowerShell v3.

Some examples and explanation are available from http://blogs.msdn.com/b/powershell/archive/2011/12/22/another-holiday-gift-from-the-powershell-team-powershell-3-0-ctp2-getting-started-with-windows-powershell-workflow.aspx


December 20, 2011  1:54 PM

Recordings, Slides and Demo scripts

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Here are the recordings, slides and demo scripts from last weeks two Live Meetings.

Introduction to WMI






Down load and unzip to find all items

December 12, 2011  3:51 PM

WMI LIKEs Wildcards

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

You may hear or read that WMI can’t accept wildcards. WRONG

WMI accepts wildcards but not the ones you might expect.



Get-Process p*

This gets all the process that begin with the letter p

To do something similar with WMI we need to use the –Filter parameter. We can get a single process like this

Get-WmiObject -Class Win32_Process -Filter "Name=’powershell.exe’"

so you may want to try this

Get-WmiObject -Class Win32_Process -Filter "Name=’p*’"


Oops no returns of any kind.

That’s because in the filter we are using WQL which uses the SQL wildcards

% = *   multiple characters

_ = ?    single character


OK then this will work

Get-WmiObject -Class Win32_Process -Filter "Name=’p%’"


Oh no it won’t because a further complication is that we have to use the WQL LIKE operator not =

Get-WmiObject -Class Win32_Process -Filter "Name LIKE ‘p%’"

And we have a winner


To use the single character wildcard (which in my experience doesn’t get used as much as the multi-character)

Get-WmiObject -Class Win32_Process -Filter "Name LIKE ‘powershell.e_e’"


And as an added bonus the title of the post give us a way to remember to use the LIKE operator.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: