dig-like functionality on windows?
13,895
Try this...
Get-Command -Name Resolve-Dns* |
Format-Table -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Resolve-DnsName 1.0.0.0 DnsClient
# Get parameters, examples, full and Online help for a cmdlet or function
(Get-Command -Name Resolve-DnsName).Parameters
Get-help -Name Resolve-DnsName -Examples
Get-help -Name Resolve-DnsName -Full
Get-help -Name Resolve-DnsName -Online
# Get all IPAddresses for the provided DNS name
$env:USERDNSDOMAIN | ForEach{Resolve-DnsName -Name $PSItem}
Name Type TTL Section IPAddress
---- ---- --- ------- ---------
CONTOSO.COM A 600 Answer 192.168....
CONTOSO.COM A 600 Answer 10.10...
#
$env:USERDNSDOMAIN |
ForEach{
# Get all IP addresses for the provided DNS name
$DNSIPA = (Resolve-DnsName -Name $PSItem).IPAddress
# Check if the host is up for a given IPA and port number
ForEach($IPA in $DNSIPA)
{
"Processing $IPA"
Test-NetConnection -ComputerName $IPA -Port 1666
}
}
Yet, this question would translate into you are new to PowerShell. So, before you cause yourself undue confusion/frustration, etc., it is vital you spend the time getting up to speed on it using all the available free PowerShell video and eBook training resources. Here are just a few.
MSDN, MSDocs, MVA, MSChannel9, YouTube, eBooks, use the help files as noted above.
Author by
Jason De Arte
Code Monkey @ The Walt Disney Company. All comments are my own and do not represent my employer. C++ and Python
Updated on June 20, 2022Comments
-
Jason De Arte almost 2 years
On a windows system, I'm trying to gather all the IP addresses for a DNS name & call a tool with each IP address. I know how to do it from a shell script - but not how to do it from a batch or powershell file.
I want to port this to windows..
#!/usr/bin/env bash # Get all the IPs for our server instance # and pass it to "p4 trust" to update the .p4trust file for address in $(dig perforce.example.com +short) do echo "processing address: $address:1666" p4 -p "ssl:$address:1666" trust -y -f || true done
Questions:
- is there a pre-installed windows
dig
equivalent that will only return the IPs of the DNS record? - in a batch or powershell file, how do you iterate over multiple results from another application?
- is there a pre-installed windows
-
Jason De Arte over 5 yearsNice! This is exactly what I was looking for. Thank you @postanote!
-
postanote over 5 yearsNo worries. Glad it will help. Just a note. Test-NetConnection is not in all versions of PowerShell and dependent on the OS you are on. If you are not on a PowerShell / OS version that has this cmdlet, you'll need to resort to the .Net TCPClient namespace to do this sort of thing, well, for the port check stuff. For Example: community.idera.com/database-tools/powershell/powertips/b/tips/…