Skip to content

Instantly share code, notes, and snippets.

@milesgratz
Created April 12, 2017 18:43
Show Gist options
  • Save milesgratz/0285a6c3e9dd2bcfbbc72b441fcb6410 to your computer and use it in GitHub Desktop.
Save milesgratz/0285a6c3e9dd2bcfbbc72b441fcb6410 to your computer and use it in GitHub Desktop.
Get-NetworkAdapter (PowerShell v2 example)
$NetAdapterList = (gwmi -Query "SELECT * FROM Win32_NetworkAdapter")
$NetAdapterConfigList = (gwmi -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")
$Results = @()
foreach ($NetAdapter in $NetAdapterList){
$NetAdapterConfig = $NetAdapterConfigList | Where-Object { $_.Index -eq $NetAdapter.DeviceID }
If ($NetAdapterConfig -ne $null)
{
$Object = New-Object PSCustomObject
$Object | Add-Member -MemberType NoteProperty -Name "Name" -Value $NetAdapter.Name -Force
$Object | Add-Member -MemberType NoteProperty -Name "MACAddress" -Value $NetAdapter.MACAddress -Force
$Object | Add-Member -MemberType NoteProperty -Name "Speed" -Value $NetAdapter.Speed -Force
$Object | Add-Member -MemberType NoteProperty -Name "DHCPEnabled" -Value $NetAdapterConfig.DHCPEnabled -Force
$Object | Add-Member -MemberType NoteProperty -Name "IPAddress" -Value $NetAdapterConfig.IPAddress -Force
$Object | Add-Member -MemberType NoteProperty -Name "DefaultIPGateway" -Value $NetAdapterConfig.DefaultIPGateway -Force
$Object | Add-Member -MemberType NoteProperty -Name "DNSDomain" -Value $NetAdapterConfig.DNSDomain -Force
$Object | Add-Member -MemberType NoteProperty -Name "Servicename" -Value $NetAdapterConfig.Servicename -Force
$Object | Add-Member -MemberType NoteProperty -Name "Description" -Value $NetAdapterConfig.Description -Force
$Object | Add-Member -MemberType NoteProperty -Name "Index" -Value $NetAdapterConfig.Index -Force
$Results += $Object
}
}
$Results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment