Gwmi win32networkadapterconfiguration select name MAC. Gwmi win32networkadapterconfiguration select macaddress etc. For Gateway, Domain and Hostname; look in 'get-wmiobject win32networkadapterconfiguration'. You should see properties like 'DefaultIPGateway' and other properties prefixed with 'DNS'. This is where the data you want is kept. Dec 09, 2008 Powershell Query or Filter WMI read only properties. Get-WmiObject Win32NetworkAdapterConfiguration -filter 'DefaultIPGateway = '192.168.0.1' format-table Ipaddress, DefaultIPGateway.
I'm creating a script that finds and displays IP configuration information. I have managed to create the variables to get the information and to display it:
I'm filtering the interface by index number, which for my case the number is 12 for the right interface. I want to prompt the user with a list of network interfaces.
Get-NetAdapter
command should not be used because it doesn't work on PowerShell v2. The user must be able to see current interfaces including descriptions and be able to select one netowrk adapter interface. The selected interface must be put into a variable i.e. $interface. The variable must output the corresponding adapter index number. After that, I am able to place the variable in the filter command like: -Filter 'index = '$interfaceindexnumber'
which should normally display IP information for the selected interface.
Feel free to use a different filter if you believe index number is not the right solution for this case. Please, make sure to use commands that work with PowerShell v2.
Thank You!
Jeff S.Jeff S.
2 Answers
Based on the description of what you are trying to do, which is to allow a user to select an interface that is later used to provide information to you or your script, I took your script and scrubbed it a little bit as well as added in Out-GridView which is great for presenting information to a user. All of these commands should work in PowerShell v2.
I started out by doing just one WMI query and storing it in a variable. Then I pass filtered information to the Out-GridView cmdlet for the user to select whichever interface they want or need to select. I chose to only show the user Description, IPAddress, and Index to prevent too much confusion.
After the user makes the selection, it is assigned to $interface. To extract the full information that was originally queried from win32_networkadapterconfiguration I used the index number of the users selection to filter against $AllNetInterfaces. This could be simplified by just passing all of the information to the Out-GridView to begin with, but again since you plan on having users make selections and such, less is more.
Finally, I call the properties of the object without using the 'Write-Host' function because at this point I am validating that it worked and I am not really sure what you are going to do with it later on.
If what you are trying to do is show the user the IP information without using ipconfig, then you could use the Out-GridView cmdlet once again, like this:
DavidHDavidH
Jeff S.Jeff S.
![Ipv6 Ipv6](/uploads/1/2/3/7/123715522/890587749.png)