- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to add new dhcp relay server from postman API
I need to add an additional DHCP server to several sites as a backup but the postman API call wipes the current values and just add the new ones.
for example, I currently have different server IPs per region and I want to add a central DHCP relay as 192.168.17.25 but when I run the API it just wipes the current values and adds just the IP.
$body = @"
{
`"dhcpHandling`": `"Relay DHCP to another server`",
`"dhcpRelayServerIps`": [
`"192.168.17.25`",
]
}
"@
$response = Invoke-RestMethod $endpointuplink -Method 'PUT' -Headers $headers -Body $body
$response | ConvertTo-Json
Anyone with a similar situation that can share any knowledge?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, the issue is that we have several different DHCP servers for several different sites so that would not work.
Fortunatelly I was able to figure this out getting the network vlan data 1st and then putting it in a variable and then concatenate the new IP. this is a snip of code, my logic can be a little weird, im just starting with this :).
#This gets the current Network Vlan values
$request = Invoke-RestMethod $endpointuplink -Method 'GET' -Headers $headers
#This code will add the "" to the DHCP IP values and format it for the API call to work correctly
[string]$servers = $null
[Array]$servers = $request.dhcpRelayServerIps
[Array]$current = '"{0}"' -f ($servers -join '","')
if ($servers -contains $newserver){
write-host("DHCP IP is duplicated")
}else {
$body = @"
{
`"dhcpRelayServerIps`": [$current,"$newserver"]
}
"@
$response = Invoke-RestMethod $endpointuplink -Method 'PUT' -Headers $headers -Body $body
$response | ConvertTo-Json
