You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 15:42:49