Last active
February 23, 2024 11:08
-
-
Save Vibhu2/4bdb0d4ee2f114b600a689e54b6c0dc6 to your computer and use it in GitHub Desktop.
this function gets details about comouter name,ip,static or dynamic and its dhcp server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-PhysicalInterfaceInfo { | |
[CmdletBinding()] | |
param() | |
begin { | |
$computerName = $env:COMPUTERNAME | |
#Write-Output ("Computer Name: $computerName") | |
$interfaceInfo = @() | |
} | |
process { | |
$interfaces = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' } | |
foreach ($interface in $interfaces) { | |
if ($interface.InterfaceDescription -notlike "*Virtual*" -and $interface.InterfaceDescription -notlike "*Pseudo*") { | |
$interfaceName = $interface.Name | |
$ipAddress = (Get-NetIPAddress -InterfaceIndex $interface.InterfaceIndex -AddressFamily IPv4).IPAddress | |
$dhcpServer = (Get-NetIPConfiguration -InterfaceIndex $interface.InterfaceIndex).Ipv4DefaultGateway.NextHop | |
$dhcpEnabled = (Get-NetIPConfiguration -InterfaceIndex $interface.InterfaceIndex).IPv4InterfaceMetric -ne 0 | |
if ($dhcpEnabled) { | |
$ipType = "Dynamic" | |
} else { | |
$ipType = "Static" | |
} | |
$interfaceInfo += [PSCustomObject]@{ | |
Computername=$computerName | |
Interface = $interfaceName | |
IPAddress = $ipAddress | |
DHCPServer = $dhcpServer | |
IPType = $ipType | |
} | |
} | |
} | |
} | |
end { | |
$interfaceInfo | Format-Table -AutoSize | |
} | |
} | |
Get-PhysicalInterfaceInfo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment