I have made a short script that will pull dns txt records down from a server and combine them into a single string. DNS txt records are:

1.website.com 2.website.com 3.website.com

Each of these are iterated through using the single digit number.
The double quotes at the beginning and the end of the strings are trimmed
This works exactly as I would like it too I am simply interested in seeing how short I can get it

$i = 1
1..2 | foreach {
sv -N v -Va ((nslookup -q=txt $w )[-1]).Trim().Trim('"')
$p += "$v"
$i += 1

and ideally I'd like to return the $p variable, that being the concatenated string

this is what I ended getting it down to

1..2|%{$p+=Resolve-DnsName "$_.website.com." -Ty TXT -EA 0|% S*s};powershell .($p)
  • \$\begingroup\$ What's the scoring criterion? \$\endgroup\$ Sep 16 at 10:17
  • \$\begingroup\$ What approaches have you already tried to shorten the code? From meta: 'Simply dumping code and saying "How can this be shorter?" is not acceptable. The poster needs to state things they've tried or point out specific parts they think could be improved.' \$\endgroup\$
    – Dingus
    Sep 16 at 14:39
  • \$\begingroup\$ edited with what I got to work eventually \$\endgroup\$ Sep 17 at 3:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.