|
Guy recommends: This CG will put you in charge of controlling changes to network routers and other SNMP devices. Download your free Config Generator |
PowerShell: More flexible than IpconfigPowerShell: More flexible than IpconfigScripting WMI objects with PowerShell is a particularly productive area. On this page I will illustrate PowerShell's capabilities by creating a script which is more flexible than Ipconfig. Topics for PowerShell: More flexible than Ipconfig
♣ Our MissionOn this page our mission is to extract TCP/IP information from a machine's network adapters using PowerShell. But first a question: 'Is Guy reinventing the wheel? Can Ipconfig, with its numerous switches, provide the same information?' To answer this question is easy, all you have to do is compare Ipconfig with my PowerShell scripts, even better, compare Ipconfig with YOUR scripts. If I could sum up the benefit of PowerShell over Ipconfig, in one word, that word would be flexibility. For example, you can customize which TCP/IP properties to display, and in addition, you can interrogate the network adapters on other machines. Can Ipconfig do that? I have not found away. PowerShell Objectives WMIObject -list (parameter to enumerate
all possible object classes) Guy's Advice Either work through my learning progression by starting with Objective 1 (recommended), or else if you are in a hurry, cut to the chase, and head for Objective 3 PowerShell: More flexible than Ipconfig. Pre-requisites and Checklist
Download
PowerShell from Microsoft's site. One interesting point is that there are different versions
of PowerShell for XP, Windows Server 2003 and Vista. Method 1 (Quick)
Method 2 (Best)
Objective 1) - List WMI ObjectsHere is a cmdlet which identifies all the Network WMI objects. $colItems = get-wmiobject -list | where {$_.name -match "network"} Learning PointsNote 1: Because PowerShell is so simple, yet so efficient, we need fewer commands than for a corresponding VBScript. Indeed, the bare minimum to get
started, and display all the WMI objects is these 8 letters with a dash in the middle: Note 2: Observe the (|) pipe. You will use this symbol hundreds of times in PowerShell, what happens is the output of the wmiobject list is pumped into the 'where' clause, which pulls out all the entries that contain the word "network". My thinking was get-wmiobject -list produces too many objects. Note 3: I deliberately don't use many aliases in my scripts, but I make an exception for ft (format-Table) because it's so useful for controlling the display of PowerShell's output. Do try the above script with, and without, the last word, 'name'. Objective 2) - WMIObject | get-Member (Discover which properties to use in our mission)This script identifies the properties available for the object: Win32_NetworkAdapterConfiguration. Here below is a classic example of the get-Member construction. $colItems = get-wmiobject -class "Win32_NetworkAdapterConfiguration" Learning PointsNote 1: Observe how -class homes in on the object that we are interested in, namely: Note 2: If you wished to manipulate the TCP/IP settings, you could investigate which methods are available by substituting 'Method' for the last word, 'Property'. Alternatively, you could omit the '-Membertype Property' phrase altogether.
|
||||
|
|
|
|
Home Copyright © 1999-2010 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |