PowerShell – Return IP, Subnet, Gateway, and DNS

email me

Function Get-IPObject
{
Get-WmiObject -class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = $true"
}

Function Format-netData($objIP)
{
"IP: " + $objIP.IPAddress[0]
"Subnet: " + $objIP.IPSubNet[0]
"GateWay: " + $objIP.DefaultIPGateway[0]
"DNS: " + $objIP.DNSServerSearchOrder[0]
}

Clear-Host

$Data = Get-IPObject

Format-netData($Data)

 


Notes

Performing Networking Tasks (Microsoft Docs)

 

DHCPEnabled :
IPAddress :
DefaultIPGateway :
DNSDomain :
ServiceName :
Description :
Index :

 

Try this

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*

DHCPLeaseExpires :
Index :
Description :
DHCPEnabled :
DHCPLeaseObtained :
DHCPServer :
DNSDomain :
DNSDomainSuffixSearchOrder :
DNSEnabledForWINSResolution :
DNSHostName :
DNSServerSearchOrder :
DomainDNSRegistrationEnabled :
FullDNSRegistrationEnabled :
IPAddress :
IPConnectionMetric :
IPEnabled :
IPFilterSecurityEnabled :
ArpAlwaysSourceRoute :
ArpUseEtherSNAP :
Caption :
DatabasePath :
DeadGWDetectEnabled :
DefaultIPGateway :
DefaultTOS :
DefaultTTL :
ForwardBufferMemory :
GatewayCostMetric :
IGMPLevel :
InterfaceIndex :
IPPortSecurityEnabled :
IPSecPermitIPProtocols :
IPSecPermitTCPPorts :
IPSecPermitUDPPorts :
IPSubnet :
IPUseZeroBroadcast :
KeepAliveInterval :
KeepAliveTime :
MACAddress :
MTU :
NumForwardPackets :
PMTUBHDetectEnabled :
PMTUDiscoveryEnabled :
ServiceName :
SettingID :
TcpipNetbiosOptions :
TcpMaxConnectRetransmissions :
TcpMaxDataRetransmissions :
TcpNumConnections :
TcpUseRFC1122UrgentPointer :
TcpWindowSize :
Scope :
Path :
Options :
ClassPath :
Properties :
SystemProperties :
Qualifiers :
Site :
Container :

 

tags: MrNetTek