Closed emyatsuna closed 3 years ago
Hi @emyatsuna, thanks for reaching out.
The tricky part with trying to get more details from the objects
field is that they're not all the same object type. So piping the _ref
fields to Get-IBObject
will work, but trying to requesting additional parameters with -ReturnFields
is difficult because you'll get an error if you add a field that is not shared by all of the object types. For instance, most objects have name
and comment
fields. So you could do something like:
Get-IBObject ipv4address -filter 'ip_address=10.10.9.2' | select -expand objects | Get-IBObject -base -fields name,comment
But not very many object types have a bootserver
field like fixedaddress does. So if you tried to add that to the list of fields, you'd get an error on the first object that didn't have it (which incidentally currently breaks the pipeline processing and I think is a bug). As an alternative, you could use the -ReturnAll
switch like this which will dynamically discover all of the fields for each type and request all of them for each one.
Get-IBObject ipv4address -filter 'ip_address=10.10.9.2' | select -expand objects | Get-IBObject -ReturnAll
As for filtering fixedaddress
records by name, unfortunately the WAPI doesn't appear to support searching by that field on that object at the moment. You can see it in the docs if you go to your grid master at the following URL, https://gridmaster/wapidoc/objects/fixedaddress.html#name
. So the only workaround is to query all of them (or a subset filtered using another field) and then do the name filtering locally in PowerShell with a Where-Object
clause like:
Get-IBObject fixedaddress -base -fields name | Where-Object { $_.name = 'server' }
Thanks for the quick response @rmbolger . I was hoping to extract fixedaddress
details having the same name
object. Your explanation and samples by adding the -base
and -ReturnAll
flags are really helpful. I can't access the url https://gridmaster/wapidoc/objects/fixedaddress.html#name though. It may be broken?
Sorry for the confusion, the help URL was intended for you to replace "gridmaster" with your own grid master's hostname. For a quick shortcut, you can also use Get-IBSchema fixedaddress -LaunchHTML
.
Another possibly more efficient way to find fixedaddress records with the same would be using PowerShell's Group-Object
function like this:
# The "Where-Object { $_.name }" portion is optional and excludes fixed addresses with no name
Get-IBObject fixedaddress -base -fields name | Where-Object { $_.name } |
Group-Object name | Where-Object { $_.Count -gt 1 } | Select-Object -expand group
We're having PowerShell group the results by name so that duplicate names are in the same group. Then, we filter out groups the results to groups with a count of 2 or more and re-expand the results.
Thank you @rmbolger your samples are really helpful! This can help us move forward with our scripts. One last question, can fixedaddress
in this module also filter a specific subnet? or it should be only for type network
?
A subnet in Infoblox is basically any network
object as seen in the IPAM or DHCP gui. fixedaddress
objects have a network
field that is filterable using either exact or regex matching in CIDR format.
So yes, you could do something like either of these:
# exact match
Get-IBObject fixedaddress -filters 'network=192.168.0.0/24' -base -fields name
# regex match
Get-IBObject fixedaddress -filters 'network~=192.168.*/24' -base -fields name
Amazing! It solves my problem. Thank you @rmbolger !
Happy to help. Feel free to post more questions if you have them.
Hi,
Thanks for this module! It helped us a lot. We're heavily using this one to automate the IP reservations in Infoblox. I have 2 questions regarding getting IPv4 details from IPAM.
We can query using the IP but it only returns _ref, ipv4addr, _networkview. Below is the example snippet. Would it be possible to expand the values to get the Name (hostname) and Status (Used/ Unused) informations?
Get-IBObject ipv4address -filter 'ip_address=10.10.9.2' | select -expand objects | Get-IBObject
Also, we would like to filter out using the IPv4 Reservation Type Name but the below script is only applicable to DNS records. Is there any way to get a full object/ data view of the IPAM IPv4 Reservation Type details using the
Get-IBObject
filtered by Name?Get-IBObject -type record:host -filters 'name=server'
Thank you.