15882

PowerShell Deep Dives

PowerShell Deep Dives is a book put together by the PowerShell community.  I’m editing one of the sections and have contributed some of the chapters. Manning have just started releasing it on their MEAP program.  The full book will hopefully be ready in the spring.

Best of all the royalties are being donated to worthwhile cause.

Check it out - http://manning.com/hicks/

PowerShell summit

April 22-14  2013 – Microsoft campus.  PowerShell team and MVPs

http://powershell.org/summit/

Tickets going fast

PowerShell Deep Dive 2012 Agenda

The agenda for the PowerShell Deep Dive next month has just been published on the PowerShell team blog

http://blogs.msdn.com/b/powershell/archive/2012/03/26/schedule-for-the-upcoming-powershell-deep-dive-and-a-few-videos-from-frankfurt.aspx

If you are already booked to go – looking forward to meeting you.  If you’re thinking of going last years event was amazing. If you are interested in PowerShell it is the place to be

PowerShell Deep Dive 2012 speaking

I heard at the beginning of the week that I’ve been granted a speaker slot at the PowerShell Deep Dive next month - http://www.theexpertsconference.com/us/2012/

I’ll be speaking on creating cmdlets from WMI objects using a new feature in PowerShell v3 that is so cool it could start a new Ice Age

Look forward to seeing you there

PowerShell Deep Dive 2012

The 2012 PowerShell Deep Dive has been announced  - April 29 – May 2 in San Diego.

http://blogs.msdn.com/b/powershell/archive/2012/01/27/it-s-time-for-another-powershell-deep-dive.aspx

 

This time PowerShell is a full track so expect more of your favourite stuff.  Hope to see you there.

Discovering NIC that has a specific IP Address

One question (of many) that came up at that European Deep Dive (more on that later) was finding the particular network adapter associated with an IP Address.  The problem is that IP Address (in the later versions of Windows) is a string array in WMI

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=7"

returns this for the IP Address

IPAddress        : {10.10.54.202, fe80::4547:ee51:7aac:521e}

So we need a bit of magic. How can we test if an array contains a particular value?

function get-nicfromIP {            
 [CmdletBinding()]            
 param (            
  [parameter(Mandatory=$true)]            
  [ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")]            
  [string]$ipaddress,            
              
  [string]$computername="$env:COMPUTERNAME"            
 )            
Write-Verbose $ipaddress            
             
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computername |            
foreach {            
 Write-Verbose "$($_.Description)"            
 if ($($_.IPAddress) -contains $ipaddress){            
  Write-Debug "getting adapter"            
              
  Get-WmiObject -Class Win32_NetworkAdapter -Filter "DeviceID=$($_.Index)" -ComputerName $computername             
 }            
}             
}


Create a function that takes an IP Address as a parameter  (thanks to Tobias for the regex – one day I’ll learn to do them)



Use the Win32_NetworkAdapterConfiguration class to retrieve the configurations. Foreach configuration test if the IPAddress array contains the IPAddress.



The –contains operator is made for this work



If our test is true then we get the Win32_NetworkAdapter that is associated with the configuration.  I’ve just used the fact that DeviceId=Index to perform the link.



Contrary to my thinking at the Deep Dive (why didn’t we test it instead of just talking about it Sad smile) there is a WMI association between the Win32_NetworkAdapterConfiguration and the Win32_NetworkAdapter  class so we could rewrite the if statement as



function get-nicfromIP {            
 [CmdletBinding()]            
 param (            
  [parameter(Mandatory=$true)]            
  [ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")]            
  [string]$ipaddress,            
              
  [string]$computername="$env:COMPUTERNAME"            
 )            
Write-Verbose $ipaddress            
             
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computername |            
foreach {            
 Write-Verbose "$($_.Description)"            
 if ($($_.IPAddress) -contains $ipaddress){            
  Write-Debug "getting adapter"            
  $q = "ASSOCIATORS OF {Win32_NetworkAdapterConfiguration.Index=$($_.Index)}"            
  Get-WmiObject -ComputerName $computername -Query $q            
 }            
}             
}

European Deep dive approaching

Next Monday & Tuesday sees the first European Deep Dive  - if you are a PowerShell fan its where you need to be.

 

The speaker line up is available from

 

http://blogs.msdn.com/b/powershell/archive/2011/10/06/powershell-deep-dive-lineup.aspx

 

See you there

Deep Dive line up

The line up for this months Deep Dive has been announced

http://blogs.msdn.com/b/powershell/archive/2011/10/06/powershell-deep-dive-lineup.aspx

 

Looks good

PowerShell Deep Dive speakers

Some more sessions have been announced for the Deep Dive

http://www.theexpertsconference.com/europe/2011/powershell-deep-dive/session-abstracts/

The speaker line up includes:

Aleksandar Nikolic

Shay Levy

Kirk Munro

Dmitry Sotnikov

Jeffery Hicks

James Brundage

Tobias Weltner

Brandon Shell

James O’Neill

Ravi Chaganti

Me

 

There will also be a significant presence from the PowerShell team.

 

If you can’t get your PowerShell questions answered here – then you won’t get them answered

The Experts Conference April 2011–My session

Dmitry has just posted the video of the session I did at the PowerShell deep dive @ TEC in April

http://dmitrysotnikov.wordpress.com/2011/09/14/video-richard-siddaway-wmi-gems-and-gotchas/

 

The session was entitled WMI: Hidden Gems and Gotchas

Links to the slides and demo scripts are also available on the post