Reply
Highlighted
Accepted Solution

PowerShell Manage DHCP IPv4 MAC Address Filters with REST

[ Edited ]
artrathke
Techie
Posts: 11
9730     0

We use DHCP IPv4 MAC Address filters.  We add them via a CSV file.  There is a manual effort involved.  We would like to write a PowerShell script to read a CSV file from another system and add and remove the filter entries in Infoblox.  I am looking for some help with the URI needed to do some REST transactions.

 

I am using this URI:

https://10.1.18.57/wapi/v2.3.1/filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRLZWxseV9NQUM:Kelly_MAC 

 

and I get this back:

 

_ref comment name
---- ------- ----
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRLZWxseV9NQUM:Kelly_MAC Whitlist of MAC addresses Kelly_MAC

 

But I don't know how to get the actual data records with the MAC addresses that are allowed.  

 

What do I need to do to be able to read, add or delete the MAC address records?

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

GHorne Community Manager
Community Manager
Posts: 248
9731     0

If you want to get all the mac addresses in a filter you would use this:

 

 

/wapi/v2.3/macfilteraddress?_return_type=json-pretty&filter=MyFilterName

 

The call you are using (/filtermac) just gets you the list of filters in the system.

 

To add a mac address to a filter you would POST an object to '/wapi/v2.3/macfilteraddress' and specify the filter to add the address to.

 

To remove a mac address you would send a DELETE to the object using the _ref.

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

[ Edited ]
artrathke
Techie
Posts: 11
9731     0

I'm still not getting what I hoped for.  I was hoping to get the list of MAC addresses.

 

When I set the $uri to: https://10.1.18.57/wapi/v2.3.1/filtermac  

 

I get:

 

_ref                                                                                                               comment                             name
----                                                                                                                 -------                                   ----
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRLZWxseV9NQUM:Kelly_MAC Whitelist of MAC addresses Kelly_MAC

 

When I set the $uri to: 

https://10.1.18.57/wapi/v2.3.1/macfilteraddress?_return_type=json-pretty&filter=Kelly_MAC 

 

I get:

PS C:\> Invoke-RestMethod -Uri $uri -Credential $credential -Method Get
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:1 char:1
+ Invoke-RestMethod -Uri $uri -Credential $credential -Method Get
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

I also get this error when I use the _ref value in the query:

https://10.1.18.57/wapi/v2.3.1/macfilteraddress?_return_type=json-pretty&filter=ZG5zLmRoY3BfbWFjX2Zp...

 

PS C:\> Invoke-RestMethod -Uri $uri -Credential $credential -Method Get
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:1 char:1
+ Invoke-RestMethod -Uri $uri -Credential $credential -Method Get
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

GHorne Community Manager
Community Manager
Posts: 248
9731     0

Can you send the exact output from the following:

 

https://10.1.18.57/wapi/v2.3.1/filtermac?_return_type=json-pretty

https://10.1.18.57/wapi/v2.3.1/filtermac

 

I think the problem may be with the formatting of your URL. (400, bad request)

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

artrathke
Techie
Posts: 11
9731     0

PS C:\> $uri="https://10.1.18.57/wapi/v2.3.1/filtermac?_return_type=json-pretty"
Invoke-RestMethod -Uri $uri -Credential $credential

_ref comment name
---- ------- ----
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRLZWxseV9NQUM:Kelly_MAC Whitelist of MAC addresses Kelly_MAC

 

PS C:\> $uri="https://10.1.18.57/wapi/v2.3.1/filtermac"
Invoke-RestMethod -Uri $uri -Credential $credential

_ref comment name
---- ------- ----
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRLZWxseV9NQUM:Kelly_MAC Whitelist of MAC addresses Kelly_MAC

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

GHorne Community Manager
Community Manager
Posts: 248
9731     0

the output should look like this:

 

[
{
"_ref":
"filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRNQUMtZmlsdGVyLTE:MAC-filter-1",
"name":
"MAC-filter-1"
},
{
"_ref":
"filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRNQUMtZmlsdGVyLTI:MAC-filter-2",
"name":
"MAC-filter-2"
},
{
"_ref":
"filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRJViBQdW1wcw:IV%20Pumps",
"name":
"IV Pumps"
},

or this

 

<list>
<value type="object">
<name>MAC-filter-1</name>
<_ref>
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRNQUMtZmlsdGVyLTE:MAC-filter-1
</_ref>
</value>
<value type="object">
<name>MAC-filter-2</name>
<_ref>
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRNQUMtZmlsdGVyLTI:MAC-filter-2
</_ref>
</value>
<value type="object">
<name>IV Pumps</name>
<_ref>
filtermac/ZG5zLmRoY3BfbWFjX2ZpbHRlciRJViBQdW1wcw:IV%20Pumps
</_ref>

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

artrathke
Techie
Posts: 11
9731     0

Yes, that's pretty much what I get, but what I am looking for is the list of MAC addresses inside the Kelly_MAC filter.  I don't see how to get to that.  We have 200+ MAC addresses loaded in that filter and I need to be able to list, add and delete those MAC addresses inside Kelly_MAC.

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

artrathke
Techie
Posts: 11
9731     0

 Here is  screen shot of the data in my system - I'm trying to manage the data in this list.

Capture.PNG

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

GHorne Community Manager
Community Manager
Posts: 248
9731     0

i wanted to check the exact name of the filter (did it have any special characters, etc)

 

This url should work:

 

https://10.1.18.57/wapi/v2.3.1/macfilteraddress?_return_type=json-pretty&filter=Kelly_MAC 

Have you tried just pasting that url into a browser? what do you get?

 

Is your cut/paste corrupting the '?','&' or other special characters ?

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

[ Edited ]
artrathke
Techie
Posts: 11
9731     0

When I paste it into the browser, here's what I get:

 

{ "Error": "AdmConProtoError: Result set too large (> 1000)", 
  "code": "Client.Ibap.Proto", 
  "text": "Result set too large (> 1000)"
}

I suppose that would throw a 400 error.  

 

I added: &_max_results=100 to the end and got the 100 records from the server.  WONDERFUL!

 

Thank you!

Re: PowerShell Manage DHCP IPv4 MAC Address Filters with REST

GHorne Community Manager
Community Manager
Posts: 248
9731     0

Yes, you should ALWAYS check the error message returned, not just the error code.

 

If your powershell library isn't getting that for you, it will need a re-write, or find a new one.

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You