#Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress
# useage = to query one or more servers use {NetIpdetails -computername server1,server2 and more}
# if you want export to csv use { NetIpdetails -computername server1,server2 | export-csv IPdetails.csv}
# for bulk operation you can use foreach and export to csv belwo is the example
########################################################
# $servers = Get-Content -Path "C:\servers.txt"
#
# $infoip =@()
# foreach ($server in $servers)
#
# {
# $infoip += NetIPdetails -computerName $server
#
# }
# $IPresult = $Infoip
# $IPresult | Export-Csv Ipd.csv
#
#############################################################
function NetIPdetails ($computerName=$env:COMPUTERNAME)
{
foreach ($Computer in $ComputerName) {
if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
try {
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer -EA Stop | ? {$_.IPEnabled}
} catch {
Write-Warning "Error occurred while querying $computer."
Continue
}
foreach ($Network in $Networks) {
$IPAddress = $Network.IpAddress[0]
$SubnetMask = $Network.IPSubnet[0]
$DefaultGateway = $Network.DefaultIPGateway
$DNSServers = $Network.DNSServerSearchOrder
$Description = $Network.Description
$WINS1 = $Network.WINSPrimaryServer
$WINS2 = $Network.WINSSecondaryServer
$WINS = @($WINS1,$WINS2)
$IsDHCPEnabled = $false
If($network.DHCPEnabled) {
$IsDHCPEnabled = $true
}
$MACAddress = $Network.MACAddress
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
$OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
$OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value ($DefaultGateway -join ",")
$OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled
$OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value ($DNSServers -join ",")
$OutputObj | Add-Member -MemberType NoteProperty -Name Description -Value $Description
$OutputObj | Add-Member -MemberType NoteProperty -Name WINSServers -Value ($WINS -join ",")
$OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
$OutputObj
}
}
}
}
##################################################End of the function###############