Hi there people!
I am struggling with trying to reshape an existing command.
Credit for this original command goes to https://www.xpertnotes.net/blog/2017/03/27/bulk-domain-look-ups-using-power-shell/.
However, what i need to do, is instead of having a TXT file spat out, i need a CSV file showing the domains listed in this order:
Domainname, Nameserver, A-record, Mx-Record.
I have tried the following but the csv file is empty.
$ErrorActionPreference = 'SilentlyContinue' # This is where we are going to put the results $logfile = "C:\Users\jonat\Desktop\DNS PROCCESSING\Output\result.txt" # If there is an old log, delete, we don't need it. Remove-Item $logfile #Pick a name server to query $nameserver = "DNSSERVER" $domains = get-content "C:\Users\jonat\Desktop\DNS PROCCESSING\INPUT-ST15.txt" # Get Busy foreach ($domain in $domains){ $domain | Out-file -filepath $logfile -Append -width 180 # NSLOOKUP COMMANDS run one or all - examples are given #nslookup -querytype=ANY $domain $nameserver | Out-file -filepath $logfile -Append -width 180 nslookup -querytype=A $domain $nameserver | Out-file -filepath $logfile -Append -width 180 #nslookup -querytype=CNAME $domain $nameserver | Out-file -filepath $logfile -Append -width 180 nslookup -querytype=NS $domain $nameserver | Out-file -filepath $logfile -Append -width 180 nslookup -querytype=MX $domain $nameserver | Out-file -filepath $logfile -Append -width 180 #nslookup -querytype=SRV $domain $nameserver | Out-file -filepath $logfile -Append -width 180 "-----------------------------------------------------------------" | Out-file -filepath $logfile -Append -width 180 " " | Out-file -filepath $logfile -Append -width 180 } #futile attempt on csv exporting Get-Process | Select-Object -Property internet name,address,mail exchanger,address | Export-Csv -Path "C:\Users\jonat\Desktop\DNS PROCCESSING\Output\result-csv.csv" -NoTypeInformation Write-host "Job Complete please view $logfile"
Right now, the command just spits out the TXT, which does contain all that i need though.
And example looks like this:
magasin.dk Server: UnKnown Address: 91.224.174.138 Name: magasin.dk Address: 193.88.99.152 Server: UnKnown Address: 91.224.174.138 magasin.dk nameserver = ns2.tdchweb.dk magasin.dk nameserver = ns1.tdchweb.dk ns2.tdchweb.dk internet address = 193.88.99.143 ns1.tdchweb.dk internet address = 193.88.99.205 Server: UnKnown Address: 91.224.174.138 magasin.dk MX preference = 20, mail exchanger = mailgw.magasin.dk mailgw.magasin.dk internet address = 194.255.89.228 -----------------------------------------------------------------
I really hope a kind soul can help me figure this out. According to the many forums i have looked at this should be simple.
Not for me however, this is my first day trying out Powershell.
The whole “Get-Process” and “Select-Object” thing, is not something i understand yet…
Hopeful regards
Jonatan