- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Add Double Quotes Around Values When Creating TXT Records using API
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 06:59 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 02:21 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 12:20 PM
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.
Re: Add Double Quotes Around Values When Creating TXT Records using API
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sunday - last edited Sunday
Hey
Sorry for the late response.
I try that, it not working, it define it on infoblox without the " around the value.
And with SPF record, for example, it has to be with "...