Are you interested in our Early Access Program (EAP)? This program allows you to preview code, test in your lab and provide feedback prior to General Availability (GA) release of all Infoblox products. If so, please click the link here.

API & Integration, DevOps,NetOps,SecOps


Creating a hostrecord using powershell

[ Edited ]
Posts: 2
926     0

Basically I am stuck at creating a next available host record via powershell.


This is how my script looks like:


if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
$certCallback = @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
public static void Ignore()
if(ServicePointManager.ServerCertificateValidationCallback ==null)
ServicePointManager.ServerCertificateValidationCallback +=
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
return true;
Add-Type $certCallback

$pwd = ConvertTo-SecureString "infoblox" -AsPlainText -Force
$creds = New-Object Management.Automation.PSCredential ('admin', $pwd)

##API variables
$Scope = ""
$Scope = ""
$Allnetwork_ref = Invoke-RestMethod "$Scope&_return_as_object=1" -Credential $creds -Method get | ConvertTo-Json
$Allnetwork_refObject = ConvertFrom-Json -InputObject $Allnetwork_ref
$Networkref = $Allnetwork_refObject.result | where {$_.status -eq 'Unused'} | Select-Object -First 1


---end first part - 


------ begin second part POST -------

$reservation_details = @{
ipv4addr = "$Networkref.ip_address"

$body = $reservation_details | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Method POST -Credential $creds -ContentType 'application/json' -Body $body


What I want to achieve is to create the next available address within the scope. I have tried many ways, but couldn't be able to get it working.


Thank you guys in advance.

Re: Creating a hostrecord using powershell

Posts: 2
927     0

Never mind guys;


I have found it and gave some extra boost to the default script. 


Success guys with developing it further.


function Ignore-SelfSignedCerts
Write-Host "Adding TrustAllCertsPolicy type." -ForegroundColor White
Add-Type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem)
return true;
Write-Host "TrustAllCertsPolicy type added." -ForegroundColor White
Write-Host $_ -ForegroundColor "Yellow"
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
} Ignore-SelfSignedCerts

$username = read-host "Please enter your name:"
$password = read-host "Enter a Password:" -assecurestring
$credential = New-Object System.Management.Automation.PSCredential($username,$password)

##API variables
$Scope = ""
$Scope = ""
$Allnetwork_ref = Invoke-RestMethod "https://i1.1.1.1/wapi/v2.6.1/ipv4address?ip_address%3E=$Scope&_return_as_object=1" -Credential $credential -Method get | ConvertTo-Json
$Allnetwork_refObject = ConvertFrom-Json -InputObject $Allnetwork_ref
$Networkref = $Allnetwork_refObject.result | where {$_.status -eq 'Unused'} | Select-Object -First 1

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
if ($_.KeyCode -eq "Enter" -or $_.KeyCode -eq "Escape"){

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,10)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Create Host record:"

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,30)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the FQDN below:"

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,50)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)

$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,70)
$objLabel2.Size = New-Object System.Drawing.Size(280,20)
$objLabel2.Text = "Please enter the IP Address below:"

$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,90)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)

$objForm.Topmost = $True



$host_details = @{
name= $objTextBox.Text
ipv4addrs=@(@{ipv4addr= $objTextBox2.Text})}

$url = ""

$body = $host_details | ConvertTo-Json

Invoke-RestMethod -Uri $url -Method POST -Credential $credential -ContentType 'application/json' -Body $body

Re: Creating a hostrecord using powershell

Posts: 179
927     0



Have you tried the WAPI call to automatically get the next available IP while creating the host record like this:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic auth")
$headers.Add("Content-Type", "application/json")

$body = "{
`n	`"name`":`"`",
`n	`"ipv4addrs`":
`n	[
`n		{
`n			`"ipv4addr`":
`n			{
`n				`"_object_function`":`"next_available_ip`",
`n				`"_parameters`":
`n				{
`n					`"exclude`":[`"`",`"`"]
`n				},
`n				`"_result_field`":`"ips`",
`n				`"_object`" : `"network`",
`n				`"_object_parameters`":
`n				{
`n					`"network`":`"`"
`n				}
`n			}
`n		}
`n	]

$response = Invoke-RestMethod 'https://grid-master/wapi/v2.11.3/record:host?_return_fields%2B=name,ipv4addrs' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json


Krishna Vasudevan

Showing results for 
Search instead for 
Did you mean: 

Recommended for You