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("") "%comspec% /c C:\Windows\system32\dnscmd.exe localhost /RecordAdd " & domain & " @ TXT v=spf1 mx ~all", 0, True
set wshell = nothing

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

It should look like:
v=spf1 mx ~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:

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?
Who is Participating?
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 ~all"
So in your VBScript, it would be (you can drop the cmd.exe btw., you can run exes by themselves): "dnscmd.exe localhost /RecordAdd " & domain & " @ TXT " & Chr(34) & "v=spf1 mx ~all" & Chr(34), 0, True
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: "%comspec% /c C:\Windows\system32\dnscmd.exe localhost /RecordAdd <string> ,0,True
Tony MassaCommented:
Are all of these "SAME as PARENT" or are the node names different than the domain name?

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.
juliandormonAuthor Commented:
Thanks oBdA that worked perfectly!
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: ("%comspec% /c dnscmd.exe localhost /RecordAdd " & domain & " @ TXT ""v=spf1 mx ~all"""), 0, True

Tony MassaCommented:
man I'm slow...
That's what I suggested
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.