Commas are inserted in DNS TXT records where spaces should be - using vb script to create DNS records

I need to add SPF records for over a thousand domains in microsft DNS.
I wrote a vd script a while back that facilitates this for me for normal a records, etc.
I modified the script to loop through all our domains and a SPF record - it's really a TXT DNS record.

Here's the code:
set wshell = createobject("wscript.shell")
wshell.run "%comspec% /c C:\Windows\system32\dnscmd.exe localhost /RecordAdd " & domain & " @ TXT v=spf1 mx a:bbbmail.com ~all", 0, True
set wshell = nothing

This adds a record, but there are commas after the spaces in the string:
v=spf1, mx, a:bbbmailout2.com, ~all

It should look like:
v=spf1 mx a:bbbmailout2.com ~all

When I manually add a record, it works fine.

When I check the record, there are no commas but it displays with line breaks like so:
v=spf1
mx
a:bbbmailout2.com
~all

I'm not sure if the VB is inserting the commas or linebreaks or the DNS MMC is interpretting the line breaks with commas.

Any suggestions?
juliandormonAsked:
Who is Participating?
 
oBdACommented:
You need quotes around the string you're trying to add.
The command as typed in a command window (always the first try if it doesn't work out in a script) would be:
dnscmd.exe localhost /RecordAdd some.domain.local " @ TXT "v=spf1 mx a:bbbmail.com ~all"
So in your VBScript, it would be (you can drop the cmd.exe btw., you can run exes by themselves):
wshell.run "dnscmd.exe localhost /RecordAdd " & domain & " @ TXT " & Chr(34) & "v=spf1 mx a:bbbmail.com ~all" & Chr(34), 0, True
0
 
peakpeakCommented:
The quotation marks after /Recordadd ...  instead.. make a string of the line from C:\Windows\system32\dnscmd.exe localhost /RecordAdd and to all and use it as:
wshell.run "%comspec% /c C:\Windows\system32\dnscmd.exe localhost /RecordAdd <string> ,0,True
0
 
Tony MassaCommented:
Are all of these "SAME as PARENT" or are the node names different than the domain name?

-TM
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
Tony MassaCommented:
I think the quotes are okay...but not sure that the @ symbol is valid in DNSCMD.
0
 
juliandormonAuthor Commented:
Thanks oBdA that worked perfectly!
0
 
Tony MassaCommented:
Nevermind about the @ symbol...I see the usage...

I think that all of the Text in the TXT record would have to be in quotes also since it's a string of text.  You have to use double quotes inside a quote to acheive that:

wshell.run ("%comspec% /c dnscmd.exe localhost /RecordAdd " & domain & " @ TXT ""v=spf1 mx a:testmail.com ~all"""), 0, True

-TM
0
 
Tony MassaCommented:
man I'm slow...
0
 
peakpeakCommented:
That's what I suggested
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.