top of page

PowerShell - Get DNS-IP-Subnet-DHCP info list of machines

  • Writer: Jon Boyette
    Jon Boyette
  • Mar 1, 2022
  • 1 min read

Save as GetDNSServer.ps1 , this script gives the information locally, follow the #command string and modify it, it will read and list from a text list of server names and output to csv

[cmdletbinding()] #Use for multiple: get-Content C:\temp\server.txt | .\GetServerDNS.ps1 | #Export-Csv c:\temp\GetServerDNS.csv -notype

param (

[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

[string[]]$ComputerName = $env:computername

)


begin {}

process {

foreach ($Computer in $ComputerName) {

if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

try {

$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer -EA Stop -Filter {IPEnabled=TRUE}

}

catch {

Write-Warning “Error occurred while querying $computer.”

Continue

}

foreach ($Network in $Networks)

{

$Description = $Network.Description

$IPAddress = $Network.IpAddress[0]

$SubnetMask = $Network.IPSubnet[0]

$DefaultGateway = $Network.DefaultIPGateway

$DNSServers = $Network.DNSServerSearchOrder

$WINS1 = $Network.WINSPrimaryServer

$WINS2 = $Network.WINSSecondaryServer

$WINSServers = “{$WINS1, $WINS2}”

If($network.DHCPEnabled) {$IsDHCPEnabled = $true} ELSE {$IsDHCPEnabled = $false}

$MACAddress = $Network.MACAddress

$OutputObj = New-Object -Type PSObject

$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

$OutputObj | Add-Member -MemberType NoteProperty -Name Description -Value $Description

$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 WINSServers -Value ($WINS -join ",")

$OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress

$OutputObj

}

}

}

}


 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page