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