Add txt record to dns server

Peizhi_Yu 6 Reputation points
2022-03-23T06:56:42.033+00:00

I want to add a txt record to dns server, but the record more than 255 char.

This is my cmdlet:

PS C:\Users\Administrator> $txt = "v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy6OAXCmjYT823gq+DXRjXdsypt7iepfl4pkvLRVN8wRwoND2Fk2aVlG+CitAeJ0nqWn7JAPjoTXpFtHnOWMN7ay/atQd+DcLLHfJkpRvsYSDQ1jkI2s7CkWF6G+nwLGJcNFndOdB8oawpppyESE7+DiZae8bDicaTK8oPU0J7iogeZ1fgvmutwNtNzZHiSgwF9euCiX6lTmGe+0oZ+gRUJnUmZevh//IZ+NyDkRV2kPxQBtM8brHUpRL1c11q/CA0kC6C3ku+Pqmf6A8CGT+qvlCeQ2lVqlBydQL5UjiixUEwkSrgUEKoKE2Hqw97WrDEJZqngtuqma9hWoAsKVbzwIDAQAB"

PS C:\Users\Administrator> $txt_part1 = $txt.Substring(0,252)
PS C:\Users\Administrator> $txt_part2 = $txt.Substring(252,$txt.Length - 252)
PS C:\Users\Administrator> Add-DnsServerResourceRecord -DescriptiveText "$txt_part1","$txt_part2" -Name test -Txt -ZoneName test.local
Add-DnsServerResourceRecord : Cannot process argument transformation on parameter 'DescriptiveText'. Cannot convert
value to type System.String.
At line:1 char:46

  • ... rverResourceRecord -DescriptiveText "$txt_part1","$txt_part2" -Name t ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidData: (:) [Add-DnsServerResourceRecord], ParameterBindingArgumentTransformationEx
    ception
  • FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-DnsServerResourceRecord

What should I do?

Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Gary Reynolds 9,621 Reputation points
    2022-03-23T08:15:23.283+00:00

    Hi @Peizhi_Yu

    You have a format error in the add record command, have a look at example 8 on the command page. https://learn.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecord?view=windowsserver2022-ps#example-8--add-a-multiline-txt-resource-record

    Add-DnsServerResourceRecord -DescriptiveText "$txt_part1`r`n$txt_part2" -Name text -Txt -ZoneName test.local  
    

    Gary.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.