PowerShell for Windows Admins


January 6, 2012  2:39 PM

WMI and CIM

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

Get-CimAssociatedInstance
Get-CimClass
Get-CimInstance
Get-CimSession
Invoke-CimMethod
New-CimInstance
New-CimSession
New-CimSessionOption
Register-CimIndicationEvent
Remove-CimInstance
Remove-CimSession
Set-CimInstance

compare these to the WMI cmdlets

Get-WmiObject
Invoke-WmiMethod
Register-WmiEvent
Remove-WmiObject
Set-WmiInstance

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

Notes


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.
Troubleshooting
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
    https://www.livemeeting.com/cc/usergroups/join
  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

Notice
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
                                                                                                                               ionMetric
———–                                                                                      —–     ———    ———
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 (
[int]$index,
[int]$metric
)
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 *

or

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

http://msmvps.com/blogs/richardsiddaway/archive/2011/12/23/1792823.aspx

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 {            
[CmdletBinding()]            
param (            
[parameter(Position=0,            
   ValueFromPipeline=$true)]            
   $InputObject,             
[string[]]$firstprop            
)            
            
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

or

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

or

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

or

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

Enjoy


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

https://skydrive.live.com/?cid=43cfa46a74cf3e96#cid=43CFA46A74CF3E96&id=43CFA46A74CF3E96%212931

 

WSMAN, WMI and CIM

https://skydrive.live.com/?cid=43cfa46a74cf3e96#cid=43CFA46A74CF3E96&id=43CFA46A74CF3E96%212933

 

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.

 

Consider

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.


December 11, 2011  2:32 PM

International WMI week

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

As far as I am concerned this is International WMI week.  I am delivering a Live Meeting session to the Corpus Christi (Texas) PowerShell group on Tuesday – An Introduction to WMI & PowerShell then on Thursday I am delivering a session to the UK PowerShell group http://msmvps.com/blogs/richardsiddaway/archive/2011/12/04/uk-powershell-group-december-2011.aspx – talking about WMI. WSMAN and the new CIM cmdlets in PowerShell v3

Hopefully both events will be recorded. I post the links to the recordings after the events.


December 11, 2011  3:57 AM

Happy Birthday PowerShell

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

With all the things happening in the last month – including the release of PowerShell v3 CTP 2 – one thing that seems to have been missed is that PowerShell is 5 years old!

Yes – its just over 5 years since the release of PowerShell v1 was announced in Barcelona at the IT Forum http://blogs.msdn.com/b/powershell/archive/2006/11/14/windows-powershell-1-0-released.aspx

We have come an awful long way in those five years:

  • a thriving, passionate and growing PowerShell community – the creation of the first PowerShell User Group was also announced in November 2006 in Barcelona. The UK group will have its fifth anniversary meeting next month!
  • PowerShell v2 released with remoting, WSMAN, jobs, transactions and increased WMI support, ISE, Modules etc
  • PowerShell v3 in CTP with workflow, CIM, cmdlets over objects, automatic module import, updatable help etc
  • PowerShell support is built into the major Microsoft products
  • third party support is growing – Quest, VMware, Citrix etc etc

PowerShell has gone from a “what’s that” technology to an “I’m going to have to learn that” technology. We still have a long way to go before is thought of as the tool of choice by the bulk of IT pros but we are heading in the right direction.

The next five years are going to be fun.


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: