Win32_NetworkAdapter is one of 7 Windows Management Instrumentation (WMI)
classes that provides access to your network card. PowerShell can
not only provide command-line access to the settings, but also show
properties such as NetConnectionStatus which are not visible in the Control Panel, or to IpConfig.
While you could interrogate
Win32_NetworkAdapter with VBScript, it is much easier and quicker to
manipulate WMI classes with PowerShell. A reminder that the master cmdlet is get-WmiObject,
indeed it's worth researching parameters and examples with get-help
get-WmiObject.
# Simple PowerShell script to display properties of your NICs. # Author: Guy Thomas # Version
3.2
February 2010 tested on PowerShell v 1.0 and 2.0
I could tell you which properties to script, but it's much better if you
learn how to view the master list, then make selections to suit your
particular needs or project.
# Script to research properties of Win32_NetworkAdapter # Author: Guy Thomas # Version 2.2
February 2010 tested on PowerShell v 1.0 and 2.0
get-WmiObject
Win32_NetworkAdapter | get-Member
Note 1: Above is a one-line command. Below is a
refinement to filter the properties that you are likely to be interested
in.
Note 2: A
reminder that even this command accepts get-Help, thus you could try:
get-Help get-Member -full. My point is that help will reveal other
options, for example -MemberType Method.
# Script to research properties of Win32_NetworkAdapter # Author: Guy Thomas # Version 2.5
February 2010 tested on PowerShell v 1.0 and 2.0
Note 1: Try substituting -MemberType Method for
-MemberType Property
Note 2: Below is an edited example of the output.
AdapterType AdapterTypeId DeviceID
InterfaceIndex MACAddress Manufacturer
MaxSpeed Name NetConnectionID
NetConnectionStatus NetEnabled NetworkAddresses
PhysicalAdapter ServiceName Speed Status StatusInfo
Guy
Recommends: WMI Monitor and Its Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, Solarwinds
have created the
WMI Monitor so that you can examine these gems of
performance information for free. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.
PowerShell Script To Test Which Network Connections are Active
# PowerShell script to check NetConnectionStatus of your active NICs # Author: Guy Thomas # Version 1.5
February 2010 tested on PowerShell v 1.0 and 2.0
Note 1: The key property is NetEnabled. In
the output we are looking for values of 'True'. For your
information the NetConnectionStatus of active NICs will be 2 and not 7.
Note 2: PowerShell has no word-wrap, thus we use
the
backtick ` to tell the command to continue on the next line.
Trap: With the backtick there should
be no space after the `.
Note 3: Observe PowerShell's trademark the (|) pipe
symbol, this means that the output of the main command is pumped into
Format-Table. I chose, NetEnabled, NetConnectionStatus, DeviceId
from the dozens of possible
Win32_NetworkAdapter properties of to display.
Note 1: The filtering is achieved through this
clause: -filter "NetConnectionStatus = 2" Actually, you
could substitute a 'Where' clause thus: Where-Object {$_.NetConnectionStatus -eq '2'}
Note 2: PowerShell has no word-wrap, thus the
backtick ` means continue on the next line. Beware, there should
be no space after the `.
Challenge: Change -computerName LocalHost to the value
of a machine on your network.
Preliminaries - Vital for Success. Decide which machine
you are configuring, this script is set for
LocalHost. Important: Your DeviceId is unlikely to be 17, so
please research and amend for your computer.
# PowerShell script to disable a NIC with a DeviceId of 17. # Author: Guy Thomas ## Version
2.3
February 2010 tested on PowerShell v 1.0 and 2.0
The additional feature of this script is that refines the search
from the broad 'Win32', to the narrower 'Win32_Network'. The
result is a list of network WMI classes.
# PowerShell example to list every WMI class matching Win32_network # Author: Guy Thomas # Version 1.5
February 2010 tested on PowerShell v 1.0 and 2.0
Note 1: In practical terms, most of the 7
network classes are disappointing. However, the class
Win32_NetworkAdapterConfiguration has the useful property of
DefaultIPGateway and IpAddress.
Guy
Recommends: WMI Monitor and Its Free!
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems. Fortunately, Solarwinds
have created the
WMI Monitor so that you can examine these gems of
performance information for free. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.
The key information that PowerShell's get-WmiObject needs is a WMI class.
These Win32_NetworkAdapter examples will help you to research
properties for your task such as NetConnectionStatus.
For pure PowerShell research remember get-Help and get-Member.
Please write in if you see errors of any kind. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.
Guy
Recommends: Orion's NPM - Network Performance Monitor
Orion's performance monitor is designed for detecting network outages.
A network-centric
view make it easy to see what's working, and what needs your attention.
This utility guides you through troubleshooting by indicating whether the
root cause is faulty equipment or resource overload.