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:
dig
equivalent that will only return the IPs of the DNS record?The dig command (Domain Information Groper) is a popular Linux utility used for performing DNS lookups. It provides more flexibility than Windows NSLookup but, unfortunately, it isn't available in Windows 10 by default. One option for using dig on Windows is to install BIND.
The dig (domain information groper) command is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the queried name server(s).
Dig and nslookup are two tools that can be used to query DNS servers. They both perform similar functions, but there are some key differences. For example, nslookup can only be used to query one DNS server at a time, while dig can query multiple DNS servers simultaneously.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With