THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

Add Double Quotes Around Values When Creating TXT Records using API

New Member
Posts: 2
562     0
Hey

I'm working on a PowerShell script to create TXT records in Infoblox, using the API.
I having trouble getting the script to add double quotes around the values.

I want the value in the TXT record ($txtValue) to be define in Infoblox with double quotes, like this: "somerecord"

I've tried several methods to ensure the quotes are added, but nothing seems to work.
Could anyone suggest how to modify the script so that the double quotes are correctly included in the value?

Here's part of the script I'm using:

$csvPath = "C:\1.csv"
$dnsRecords = Import-Csv -Path $csvPath

foreach ($record in $dnsRecords) {
    $txtName = $record.Name
    $txtValue = $record.Value
    $body = "{"name":"$txtName","text":"$txtValue"}"

    try {
        $response = Invoke-WebRequest 'https://some-ip/wapi/v2.1/record:txt?_return_fields%2B=name,text&_return_as_object=1' -Method 'POST' -Headers $headers -Body $body
        Write-Host "TXT record" $txtName "," $txtValue " created successfully" -ForegroundColor Green
    } catch {
        Write-Host "Failed to create TXT record" $txtName $txtValue -ForegroundColor Red
    }
}

Thanks.

Re: Add Double Quotes Around Values When Creating TXT Records using API

New Member
Posts: 2
563     0

Adding thought..

Maybe there is not obligate to add " around TXT records?
Maybe infoblox add the " by itself?

 

Re: Add Double Quotes Around Values When Creating TXT Records using API

Moderator
Moderator
Posts: 315
563     0

In powershell you can typically use a back-tick character to escape the double quotes.  In other words, to tell Powershell that the next thing coming should be the literal character.

 

So the line:

$body = "{"name":"$txtName","text":"$txtValue"}"

 

could be written like this if you want to wrap the whole value in quotes.

$body = "{"name":"$txtName","text":`"$txtValue`"}"

 

Whether or not you need to add double quptes is a bit of a different conversation, it depend on the string and what it is being used for.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You