如何使用Add-DnsServerResourceRecord为单个TXT DNS资源记录添加多段独立DescriptiveText内容
Solution for Multi-Segment TXT Record with Add-DnsServerResourceRecord
Let's fix this directly: the correct way to create a single TXT record with multiple quoted segments is to pass a string array to the -DescriptiveText parameter, but you need to format the array correctly so PowerShell doesn't misparse it.
Working Command
Use an explicit array with @() or store the array in a variable first—both methods will create the single multi-segment TXT record you need:
Option 1: Direct Array Passing
Add-DNSServerResourceRecord -DescriptiveText @("a", "b", "c", "d") -Name "identifier" -Txt -ZoneName $ZONE -ZoneScope $ZONE_SCOPE -TimeToLive 0:1:0:0
Option 2: Array in Variable
$txtSegments = @("a", "b", "c", "d") Add-DNSServerResourceRecord -DescriptiveText $txtSegments -Name "identifier" -Txt -ZoneName $ZONE -ZoneScope $ZONE_SCOPE -TimeToLive 0:1:0:0
Why Your Previous Attempts Failed
- Unquoted array (
"a","b","c","d"): PowerShell interprets"b"as the next positional parameter instead of part of-DescriptiveText's value, causing the error. Wrapping with@()explicitly tells PowerShell this is a single array argument for the parameter. - Manual quote formatting: Adding quotes to your string (e.g.,
"\"a\" \"b\"") will only include those quotes as literal text in the TXT segment, not create separate quoted segments. - Individual command calls: Each call creates a separate TXT record, which isn't what you need—DNS allows multiple segments within a single TXT record, not multiple distinct records.
Verify the Result
After running the correct command, query the record to confirm it works as expected:
Get-DnsServerResourceRecord -Name "identifier" -ZoneName $ZONE -ZoneScope $ZONE_SCOPE -RRType Txt
You'll see the RecordData.DescriptiveText property is an array, and standard DNS queries will return it as TXT "a" "b" "c" "d" exactly as you wanted.
内容的提问来源于stack exchange,提问作者RedLaser
相关产品推荐
相关产品推荐

