I've found lots of info using Win32_NetworkAdapterConfiguration, and this
gets me most of what I want. But I can't find the 'name' in this object.
How do I get this name? Or is there a way I can get the NICs
Win32_NetworkAdapterConfiguration object with the given name. Either will
work with with I'm doing.
Thx,
Perry
Does this suit your needs?
gwmi Win32_NetworkAdapterConfiguration | select Caption
"tojo2000" wrote:
No...not quite. This shows me the different adapters. But I want to be
able to find configuration information on a specific adapter based on the
'ipconfig' adapter name. I've not found a way to show this name (typically
'Local Area Connection') in the NEtworkAdapterConfiguration object.
#http://www.microsoft.com/technet/scriptcenter/scripts/msh/network/client/list/default.mspx?mfr=true
#List all network properties
$strComputer = "localhost"
$colItems = get-wmiobject -query "Select * From
Win32_NetworkAdapterConfiguration Where IPEnabled = 1" -namespace
"root\cimv2" -computername $strComputer
foreach ($objItem in $colItems)
{
write-host "Caption: " $objItem.Caption
write-host "Description: " $objItem.Description
write-host "Index: " $objItem.Index
write-host "MAC Address: " $objItem.MACAddress
write-host "MAC Address: " $objItem.DNSServerSearchOrder
}
Steve Schofield
"pschmidt" <psch...@discussions.microsoft.com> wrote in message
news:50CEE4E6-E92F-493D...@microsoft.com...
This is similar to a script I'm already using. And it prints a lot of info,
but does the $objitem below have a field for the same that prints and you use
to ID adaptors with the ipconfig command - Again, local area connection is
the 'common' name for this. This below doesn't show this name. That's the
name I'm trying to index off of or search for.
It's the same as the 'netsh interface show interface' name. What's the WMI
object/property for this?
It doesn't look like WMI grabs this information. You'll probably have
to go to the Registry if you want to get it:
Key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\<GUID>
\Connection
Value: Name
Replace <GUID> with the GUID property of
Win32_NetworkAdapterConfiguration or the SettingID property of
Win32_NetworkAdapter
gwmi -query "Select * from Win32_NetworkAdapterConfiguration where
IPEnabled = 1" |
%{$_; gwmi -query "Select * from Win32_NetworkAdapter where Index = $
($_.Index)"; Write-Host "`n`n---------------------------`n`n"} |
select *
That will give you all of the properties for Network Adapters in WMI,
with the possible exception of the Protocol classes, but the name
isn't in there, either.
gci HKLM:\SYSTEM\CurrentControlSet\Control\Network\*\*\Connection |
%{$_.GetValue("Name")}
The * elements in the path are because under the network key we have GUID
keys containing other GUIDs. The highest-level GUID is apparently universal
for the supported network adapters, and is this:
{4D36E972-E325-11CE-BFC1-08002BE10318}
So you could use this instead for the path to individual connection keys:
HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\*\Connection
So here's where it gets complicated. The Connection keys for each active
adapter contain several values: Name, DefaultNameIndex, DefaultNameId, and
PnpInstanceID. The PnpInstanceID value looks equivalent to
Win32_NetworkAdapter's PNPDeviceID value. This means that starting from
network adapters in WMI, you could grab the PNPDeviceID, and match it up to
the value in the registry.
Frankly, I'm not sure _where_ you are going with this, and that information
is critical to understand what will get you where you want to be. My guess
is that you want to take the info returned from WMI and display it with
connection names that match those shown in Windows on network connections,
allowing someone to easily correlate the two. Given that, I bet you're
collecting info from WMI, and then want to match each item to a display
name. So here's how I would proceed next.
I would just create a hash table to map names from the PnP string to the
display name. The following should do it; note that the second statement
gives a LOT of wrapping.
$IdNameHash = @{}
gci
"HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\*\Connection"
| ?{$_.property -contains "PnpInstanceID"} |
%{$IdNameHash[$_.GetValue("PnpInstanceID")] = $_.GetValue("Name")}
This gives you a hash that looks a bit like this:
Name Value
---- -----
ROOT\VMWARE\0000 VMware Network Adapter VMnet1
USB\VID_07B2&PID_5120\6&F89... Local Area Connection 2
ROOT\VMWARE\0001 VMware Network Adapter VMnet8
BTH\MS_BTHPAN\7&312B9B52&0&2 Bluetooth Network Connection
PCI\VEN_10EC&DEV_8168&SUBSY... Local Area Connection
The problem at this point is that even though you retrieve
Win32_NetworkAdapter entries and match up PnP devices, there are several
limitations. The devices shown from the registry do not include any
tunneling adapters, etc (although that may because mine are all inactive).
It might actually be because as software constructs, they don't have a true
PnP ID. That doesn't explain why my VMware connections both show up,
however.
Depending on what you're trying to do, it may be possible to simply ignore
the adapters that don't have displayed strings. I'm not happy with that
approach though.
"pschmidt" <psch...@discussions.microsoft.com> wrote in message
news:ED320033-F3B0-4615...@microsoft.com...
Just FYI - what I'm doing is the 'ipconfig' name (for lack of a better term)
is what is easily manipulated and what the setup/netsh command has changed.
So it's easy to ID and common for the different systems we have - all the
'public' NICs have the network interface name of 'public', and private
'private'. Well, there's a command which needs the name which is equivalent
to the NetworkAdaptorConfiguration name of .Description. So I need to parse
the network adaptors and find the ones which match the adaptor I'm looking
for by the name 'publc' (or 'private') and then pull the .description to so
we can use that for the setup command.
Unfortunately it's not just listing things... :(
Thanks for the info - I'll have to read it a few times :)
Perry
It's a combination on two WMI calls (I'm sure one can merge them into one):
PS > gwmi Win32_NetworkAdapter -filter "netconnectionid is not null"| select
netconnectionid,interfaceindex | ft -auto
netconnectionid interfaceindex
--------------- --------------
Local Area Connection 10
Bluetooth Network Connection 13
Wireless Network Connection 14
Local Area Connection 19
Now you can issue a second WMI call to the interface you need:
PS > gwmi Win32_NetworkAdapterConfiguration -filter "interfaceindex=10"
DHCPEnabled : True
IPAddress :
DefaultIPGateway :
DNSDomain :
ServiceName : e1express
Description : Intel(R) 82566MM Gigabit Network Connection
Index : 4
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
p> I'm trying to find a way to list the network adapter information
p> based on the ethernet adapter as listed by ipconfig - the 'defaults'
p> are 'Local Area Connection', Local Area Connection 2', etc...
p>
p> I've found lots of info using Win32_NetworkAdapterConfiguration, and
p> this gets me most of what I want. But I can't find the 'name' in
p> this object. How do I get this name? Or is there a way I can get
p> the NICs Win32_NetworkAdapterConfiguration object with the given
p> name. Either will work with with I'm doing.
p>
p> Thx,
p>
p> Perry
p>
$nics = gwmi Win32_NetworkAdapter -f "netconnectionid is not null"
$nics |%
{$_.netconnectionid;$_.GetRelated('Win32_NetworkAdapterConfiguration')}
Enjoy,
Greetings /\/\o\/\/
http://thePowerShellGuy.com
"Shay Levy [MVP]" <n...@addre.ss> wrote in message
news:95d808933de1e8...@news.microsoft.com...
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
>> It's a combination on two WMI calls (I'm sure one can merge them into
>> one):
>>
o> $nics = gwmi Win32_NetworkAdapter -f "netconnectionid is not null"
o> $nics |%
o> {$_.netconnectionid;$_.GetRelated('Win32_NetworkAdapterConfiguration'
o> )}
o>
o> Enjoy,
o>
o> Greetings /\/\o\/\/
o> http://thePowerShellGuy.com
o> "Shay Levy [MVP]" <n...@addre.ss> wrote in message
o> news:95d808933de1e8...@news.microsoft.com...
o>
"pschmidt" <psch...@discussions.microsoft.com> wrote in message
news:A58BC510-4DCA-4000...@microsoft.com...
gwmi win32_NetworkAdapter | fl *
before all my registry digging. ; )
"Shay Levy [MVP]" <n...@addre.ss> wrote in message
news:95d808933de1e8...@news.microsoft.com...
And thanks to Alex's post a little later, found 'Name' on the NetworkAdaptor
which is what I wanted - mapping from netconnectionid to name - once I know
what the objects call them :)
> gwmi win32_NetworkAdapter -filter "netconnectionid is not null" | select netconnectionid,Name | ft -auto
netconnectionid Name
--------------- ----
Enterprise Broadcom BCM5708S NetXtreme II GigE (NDIS VBD Client)
Private Broadcom BCM5708S NetXtreme II GigE (NDIS VBD Client) #2
Now I have to figure how this power-shell stuff. First time using it. Yet
anoter scripting language to learn :)
Thanks for all the help folks.
Perry
> gwmi win32_NetworkAdapter -filter "NetConnectionID is not null" | select netconnectionid,Name | ft -auto
netconnectionid Name
--------------- ----
Enterprise Broadcom BCM5708S NetXtreme II GigE (NDIS VBD Client)
Private Broadcom BCM5708S NetXtreme II GigE (NDIS VBD Client) #2
------------------------------------
How do I write the filter to say netconnectionid = Enterprise??
I tried the obvious:
> gwmi win32_NetworkAdapter -filter "NetConnectionID=enterprise" | select netconnectionid,Name | ft -auto
Get-WmiObject : Invalid query
At line:1 char:5
+ gwmi <<<< win32_NetworkAdapter -filter "NetConnectionID=enterprise" |
select
netconnectionid,Name | ft -auto
-----------------
Obviously doesn't work. Sorry - this powershell stuff is new to me...
Thx,
Perry
Sorry - I'm an idiot - netconnecitonid, not networkconnectionid.
That works great....duh.
The -filter parameter specifies a where clause to use as a filter (in WQL
syntax). You are already familar with filters against 'not null' values ("netconnectionid
is not null"), same as for 'null' values ("netconnectionid is null"). Here
are some more examples:
# Get a specific service name
PS > gwmi win32_service -filter "name='w3svc'" | select name
name
----
W3SVC
This is also valid:
PS > $svcName = "w3svc"
PS > gwmi win32_service -filter "name='$svcName'" | select name
name
----
W3SVC
PowerShell has the '*' as the -like wildcard character, WMI's like character
is '%':
# Starts with 'cc'
PS > gwmi win32_service -filter "name like 'cc%'" | select name
name
----
ccEvtMgr
CcmExec
ccSetMgr
# Ends with 'svc'
PS > gwmi win32_service -filter "name like '%svc'" | select name
name
----
AeLookupSvc
AppHostSvc
CertPropSvc
(...)
# Contains the letters 'ms'
PS > gwmi win32_service -filter "name like '%ms%'" | select name
name
----
COMSysApp
hkmsvc
MSDTC
(...)
#Exception query, return all services except those whose names start with
x, y, or z:
PS > gwmi win32_service -filter "name like '[^xyz]%'" | select name
# Single character wildcard, the underscore (_) represent any single character
in a string
PS > gwmi win32_service -filter "name like 'w___c'" | select name
name
----
W3SVC
WMSvc
Hope this helps
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
p> Sorry - I'm an idiot - netconnecitonid, not networkconnectionid.
p>
p> That works great....duh.
p>
p> "pschmidt" wrote:
p>
That works in V2 CTP2. In V1 we need to use PSBASE property to access
base members (in this case GetRelated method).
$nics = gwmi Win32_NetworkAdapter -f "netconnectionid is not null"
$nics |% {$_.netconnectionid;
$_.psbase.GetRelated('Win32_NetworkAdapterConfiguration')}
-aleksandar
http://powershellers.blogspot.com