This had me stumped for about 30 minutes, until I finally worked out the correct syntax to make this all work.
I was looking for a way to create a TXT record on my DNS server. The data though is a multi-line record – and had to be multi-line for the server to understand the response. Single line are easy – but the multi-line really threw me.
The trick is `r`n – this inserts a carriage return and line feed into the string. I was using a apostrophe at first and wondering why it wasn’t working. It isn’t, it is a grave accent, ASCII 96.
So, as an example:
$txtdata = "line1`r`nline2`r`nline3" Add-DnsServerResourceRecord -ZoneName testdomain.internal -Name MyNewTXTRecord -Txt -DescriptiveText $txtdata
This gives you a record that looks like this in Windows DNS.
It would appear at the minute that this command limits the length of the DescriptiveText parameter to 255 charactors. This is maximum string length, per line. PowerShell interprets this as the maximum length overall though.