Uriel Cohen
Uriel Cohen

Reputation: 13

Add Double Quotes Around Values When Creating TXT Records in Infoblox using API

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.

Upvotes: 0

Views: 51

Answers (0)

Related Questions