├── LICENSE.txt ├── README.md └── cmdlets ├── Add-IBResourceRecordA.ps1 ├── Add-IBResourceRecordCName.ps1 ├── Add-IBResourceRecordHost.ps1 ├── Get-IBResourceRecord.ps1 ├── Remove-IBResourceRecord.ps1 └── Set-IBResourceRecord.ps1 /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Anders Wahlqvist 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Infoblox-PowerShell-Module 2 | ========================== 3 | 4 | PowerShell Module for Infoblox 5 | 6 | Infoblox is a DNS/DHCP/IPAM appliance which really needs a proper PowerShell module. 7 | 8 | This project aims to build with based on the REST-based API they have provided at: 9 | https://community.infoblox.com/resource/getting-started-infoblox-web-api-wapi 10 | 11 | Something similiar to: 12 | http://technet.microsoft.com/en-us/library/jj649850.aspx 13 | 14 | would be perfect! 15 | -------------------------------------------------------------------------------- /cmdlets/Add-IBResourceRecordA.ps1: -------------------------------------------------------------------------------- 1 | function Add-IBResourceRecordA 2 | { 3 | 4 | <# 5 | .SYNOPSIS 6 | Adds a A record on the Infoblox Gridserver 7 | 8 | .DESCRIPTION 9 | This cmdlet creates a CName record on the Infoblox Gridserver. 10 | 11 | .EXAMPLE 12 | Add-IBResourceRecordCName -IPv4Address 1.2.3.4 -HostName myserver.mydomain.com -GridServer myinfoblox.mydomain.com -Credential $Credential 13 | 14 | .PARAMETER IPv4Address 15 | The IPv4 address for the host record. Allows pipeline input. 16 | 17 | .PARAMETER HostName 18 | The hostname for the host record. Allows pipeline input. 19 | 20 | .PARAMETER GridServer 21 | The name of the infoblox appliance. Allows pipeline input. 22 | 23 | .PARAMETER Credential 24 | Add a Powershell credential object (created with for example Get-Credential). Allows pipeline input. 25 | 26 | #> 27 | 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 31 | $IPv4Address, 32 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 33 | [Alias('name')] 34 | $HostName, 35 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 36 | [string] $GridServer, 37 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 38 | [System.Management.Automation.PSCredential] $Credential) 39 | 40 | BEGIN { } 41 | 42 | PROCESS { 43 | 44 | $InfobloxURI = "https://$GridServer/wapi/v1.2.1/record:a" 45 | 46 | $Data = "{`"ipv4addr`":'$IPv4Address',`"name`":'$HostName'}" | ConvertFrom-Json | ConvertTo-Json 47 | 48 | $WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Post -Body $Data -ContentType "application/json" -Credential $Credential 49 | 50 | if ($WebReqeust.StatusCode -ne 201) { 51 | Write-Error "Request to Infoblox failed for record $HostName!" 52 | return 53 | } 54 | } 55 | 56 | END { } 57 | } 58 | -------------------------------------------------------------------------------- /cmdlets/Add-IBResourceRecordCName.ps1: -------------------------------------------------------------------------------- 1 | function Add-IBResourceRecordCName 2 | { 3 | 4 | <# 5 | .SYNOPSIS 6 | Adds a CNAME record on the Infoblox Gridserver 7 | 8 | .DESCRIPTION 9 | This cmdlet creates a CName record on the Infoblox Gridserver. 10 | 11 | .EXAMPLE 12 | Add-IBResourceRecordCName -IPv4Address 1.2.3.4 -HostName myserver.mydomain.com -GridServer myinfoblox.mydomain.com -Credential $Credential 13 | 14 | .PARAMETER IPv4Address 15 | The IPv4 address for the host record. Allows pipeline input. 16 | 17 | .PARAMETER HostName 18 | The hostname for the host record. Allows pipeline input. 19 | 20 | .PARAMETER GridServer 21 | The name of the infoblox appliance. Allows pipeline input. 22 | 23 | .PARAMETER Credential 24 | Add a Powershell credential object (created with for example Get-Credential). Allows pipeline input. 25 | 26 | #> 27 | 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 31 | [Alias('name')] 32 | $HostName, 33 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 34 | $Canonical, 35 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 36 | [string] $GridServer, 37 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 38 | [System.Management.Automation.PSCredential] $Credential) 39 | 40 | BEGIN { } 41 | 42 | PROCESS { 43 | 44 | $InfobloxURI = "https://$GridServer/wapi/v1.2.1/record:cname" 45 | 46 | $Data = "{`"name`":'$HostName',`"canonical`":'$Canonical'}" | ConvertFrom-Json | ConvertTo-Json 47 | 48 | $WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Post -Body $Data -ContentType "application/json" -Credential $Credential 49 | 50 | if ($WebReqeust.StatusCode -ne 201) { 51 | Write-Error "Request to Infoblox failed for record $HostName!" 52 | return 53 | } 54 | } 55 | 56 | END { } 57 | } 58 | -------------------------------------------------------------------------------- /cmdlets/Add-IBResourceRecordHost.ps1: -------------------------------------------------------------------------------- 1 | function Add-IBResourceRecordHost 2 | { 3 | 4 | <# 5 | .SYNOPSIS 6 | Add a host record on the Infoblox Gridserver 7 | 8 | .DESCRIPTION 9 | This cmdlet creates a host object on the Infoblox Gridserver. 10 | 11 | .EXAMPLE 12 | Add-InfoBloxHostRecord -IPv4Address 1.2.3.4 -HostName myserver.mydomain.com -GridServer myinfoblox.mydomain.com -Credential $Credential 13 | 14 | .PARAMETER IPv4Address 15 | The IPv4 address for the host record. Allows pipeline input. 16 | 17 | .PARAMETER HostName 18 | The hostname for the host record. Allows pipeline input. 19 | 20 | .PARAMETER GridServer 21 | The name of the infoblox appliance. Allows pipeline input. 22 | 23 | .PARAMETER Credential 24 | Add a Powershell credential object (created with for example Get-Credential). Allows pipeline input. 25 | 26 | #> 27 | 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 31 | $IPv4Address, 32 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 33 | [Alias('name')] 34 | $HostName, 35 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 36 | [string] $GridServer, 37 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 38 | [System.Management.Automation.PSCredential] $Credential) 39 | 40 | BEGIN { } 41 | 42 | PROCESS { 43 | 44 | $InfobloxURI = "https://$GridServer/wapi/v1.2.1/record:host" 45 | 46 | $Data = "{`"ipv4addrs`":[{`"ipv4addr`":'$IPv4Address'}],`"name`":'$HostName'}" | ConvertFrom-Json | ConvertTo-Json 47 | 48 | $WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Post -Body $Data -ContentType "application/json" -Credential $Credential 49 | 50 | if ($WebReqeust.StatusCode -ne 201) { 51 | Write-Error "Request to Infoblox failed for record $HostName!" 52 | return 53 | } 54 | } 55 | 56 | END { } 57 | } 58 | -------------------------------------------------------------------------------- /cmdlets/Get-IBResourceRecord.ps1: -------------------------------------------------------------------------------- 1 | function Get-IBResourceRecord 2 | { 3 | 4 | <# 5 | .SYNOPSIS 6 | Retrieves resource records from a Infoblox Gridserver 7 | 8 | .DESCRIPTION 9 | Specify an attribute to search for, for example hostname and retrieve the object from the Gridserver 10 | 11 | .EXAMPLE 12 | Get-InfoBloxRecord -RecordType host -RecordName MyServer -GridServer myinfoblox.mydomain.com -Credential $Credential 13 | 14 | .EXAMPLE 15 | Get-InfoBloxRecord -RecordType network -RecordName 1.0.0.0/8 -GridServer myinfoblox.mydomain.com -Credential $Credential -Passthrough 16 | 17 | .PARAMETER RecordType 18 | Specify the type of record, for example host or network. 19 | 20 | .PARAMETER SearchField 21 | The field where the RecordValue is. Default is "Name". 22 | 23 | .PARAMETER RecordValue 24 | The value to search for. 25 | 26 | .PARAMETER GridServer 27 | The name of the infoblox appliance. 28 | 29 | .PARAMETER Properties 30 | What properties should be included? 31 | 32 | .PARAMETER Credential 33 | Add a Powershell credential object (created with for example Get-Credential). 34 | 35 | .PARAMETER Passthrough 36 | Includes credentials and gridserver in the object sent down the pipeline so you don't need to add them in the next cmdlet. 37 | 38 | #> 39 | 40 | [CmdletBinding()] 41 | 42 | param( 43 | [Parameter(Mandatory=$True)] 44 | [ValidateSet("A","AAAA","CName","DName","DNSKEY","DS","Host","LBDN","MX","NAPTR","NS","NSEC","NSEC3","NSEC3PARAM","PTR","RRSIG","SRV","TXT")] 45 | [string] $RecordType, 46 | [Parameter(Mandatory=$false)] 47 | $SearchField = 'name', 48 | [Parameter(Mandatory=$True)] 49 | $RecordValue, 50 | [Parameter(Mandatory=$True)] 51 | $GridServer, 52 | [Parameter(Mandatory=$false)] 53 | $Properties, 54 | [switch] $Passthrough, 55 | [Parameter(Mandatory=$True)] 56 | $Credential) 57 | 58 | BEGIN { } 59 | 60 | PROCESS { 61 | 62 | Write-Verbose "Building resource record search query..." 63 | $InfobloxURI = "https://$GridServer/wapi/v1.2.1/record:$($RecordType.ToLower())`?$($SearchField.ToLower())~=$RecordValue" 64 | 65 | if ($Properties -ne $null) { 66 | Write-Verbose "Adding return fields/properties..." 67 | $InfobloxURI = $InfobloxURI + "&_return_fields=$(($Properties -join "," -replace " ").ToLower())" 68 | } 69 | 70 | Write-Verbose "Initiating webrequest to API..." 71 | 72 | $WebRequest = Invoke-WebRequest -Uri $InfobloxURI -Credential $Credential 73 | 74 | Write-Verbose "Checking status code..." 75 | 76 | if ($WebRequest.StatusCode -eq 200) { 77 | Write-Verbose "Statuscode OK. Converting from Json..." 78 | $RecordObj = $WebRequest.Content | ConvertFrom-Json -ErrorAction Stop 79 | } 80 | else { 81 | Write-Error "Request to Infoblox failed (response code is not 200). See error above for details." 82 | Write-Debug "Request just failed (response not 200 or Json version failed). Please debug." 83 | return 84 | } 85 | 86 | 87 | Write-Verbose "Looping through returned objects..." 88 | 89 | foreach ($Record in $RecordObj) { 90 | 91 | $returnObject = $null 92 | $returnObject = $Record 93 | 94 | if ($Passthrough -eq $true) { 95 | Write-Verbose "Adding credentials/gridserver to the pipeline..." 96 | $returnObject | Add-Member -Type NoteProperty -Name Credential -Value $Credential 97 | $returnObject | Add-Member -Type NoteProperty -Name GridServer -Value $GridServer 98 | } 99 | 100 | Write-Verbose "Sending object to the pipeline..." 101 | Write-Output $returnObject 102 | } 103 | } 104 | 105 | END { 106 | Write-Verbose "Finished." 107 | } 108 | 109 | } 110 | 111 | -------------------------------------------------------------------------------- /cmdlets/Remove-IBResourceRecord.ps1: -------------------------------------------------------------------------------- 1 | function Remove-IBResourceRecord 2 | { 3 | 4 | <# 5 | .SYNOPSIS 6 | Removes a host record from the Infoblox Gridserver 7 | 8 | .DESCRIPTION 9 | This cmdlet removes a host object from the Infoblox Gridserver. 10 | 11 | .EXAMPLE 12 | Get-InfoBloxRecord -RecordType host -RecordName MyHost -GridServer myinfoblox.mydomain.com -Credential $Credential -Passthrough | Remove-InfoBloxRecord 13 | 14 | .PARAMETER Reference 15 | The object reference for the host record. Allows pipeline input. 16 | 17 | .PARAMETER GridServer 18 | The name of the infoblox appliance. Allows pipeline input. 19 | 20 | .PARAMETER Credential 21 | Add a Powershell credential object (created with for example Get-Credential). Allows pipeline input. 22 | 23 | #> 24 | 25 | [CmdletBinding()] 26 | param( 27 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 28 | [Alias('_ref')] 29 | [string] $Reference, 30 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 31 | [string] $GridServer, 32 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 33 | [System.Management.Automation.PSCredential] $Credential) 34 | 35 | BEGIN { } 36 | 37 | PROCESS { 38 | $InfobloxURI = "https://$GridServer/wapi/v1.2.1/$Reference" 39 | 40 | $WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Delete -Credential $Credential 41 | 42 | if ($WebReqeust.StatusCode -eq 200) { 43 | $RecordObj = $WebReqeust.Content | ConvertFrom-Json 44 | } 45 | else { 46 | Write-Error "Request to Infoblox failed!" 47 | return 48 | } 49 | } 50 | 51 | END { } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /cmdlets/Set-IBResourceRecord.ps1: -------------------------------------------------------------------------------- 1 | function Set-IBResourceRecord 2 | { 3 | 4 | <# 5 | .SYNOPSIS 6 | Changes a host record on the Infoblox Gridserver 7 | 8 | .DESCRIPTION 9 | This cmdlet changes a host object on the Infoblox Gridserver. 10 | 11 | .EXAMPLE 12 | Set-InfoBloxRecord -Reference Reference -IPv4Address 1.2.3.4 -HostName myhost.mydomain.com -GridServer myinfoblox.mydomain.com -Credential $Credential 13 | 14 | .EXAMPLE 15 | Get-InfoBloxRecord -RecordType host -RecordName MyHost -GridServer myinfoblox.mydomain.com -Credential $Credential -Passthrough | Set-InfoBloxRecord -IPv4Address 2.3.4.5 16 | 17 | .PARAMETER IPv4Address 18 | The new IPv4 address for the host record. 19 | 20 | .PARAMETER HostName 21 | The new HostName for the host record. 22 | 23 | .PARAMETER Reference 24 | The object reference for the host record. Allows pipeline input. 25 | 26 | .PARAMETER GridServer 27 | The name of the infoblox appliance. Allows pipeline input. 28 | 29 | .PARAMETER Credential 30 | Add a Powershell credential object (created with for example Get-Credential). Allows pipeline input. 31 | 32 | #> 33 | 34 | [CmdletBinding()] 35 | param( 36 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 37 | [Alias('_ref')] 38 | [string] $Reference, 39 | [Parameter(Mandatory=$True)] 40 | [string] $IPv4Address, 41 | [Parameter(Mandatory=$False)] 42 | [string] $HostName, 43 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 44 | [string] $GridServer, 45 | [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 46 | [System.Management.Automation.PSCredential] $Credential) 47 | 48 | BEGIN { } 49 | 50 | PROCESS { 51 | $InfobloxURI = "https://$GridServer/wapi/v1.2.1/$Reference" 52 | 53 | $Data = "{`"ipv4addrs`":[{`"ipv4addr`":'$IPv4Address'}] }" | ConvertFrom-Json | ConvertTo-Json 54 | 55 | $WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Put -Body $Data -Credential $Credential 56 | 57 | if ($WebReqeust.StatusCode -eq 200) { 58 | $RecordObj = $WebReqeust.Content | ConvertFrom-Json 59 | } 60 | else { 61 | Write-Error "Request to Infoblox failed!" 62 | return 63 | } 64 | } 65 | 66 | END { } 67 | 68 | } 69 | --------------------------------------------------------------------------------