- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
WAPI: Create Network Container with Active Directory Site assigned
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2022 03:55 AM
Hello everybody,
I create a network container in Powershell with:
$domain = "gridmaster.example" $network = "10.1.2.0/24" $name = "Test Network" $api_call = https://$domain/wapi/v2.10/networkcontainer $body = '{"network":"' + $network + '","comment":"' +$name + '"}' $api_results = Invoke-RestMethod -Uri $api_call -Method POST -ContentType 'application/json' -WebSession $authcookie -Body $body
But I would also like to assign an Active Directory Site, but I have no idea how to do that. Can somebody point me into the right direction?
Re: WAPI: Create Network Container with Active Directory Site assigned
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2022 05:50 AM - edited 09-26-2022 05:59 AM
I think I have to use the "move_subnets" function after creating the network container, but sadly my code does not work (HTTP 400):
$search_url = "https://$domain/wapi/v2.10/msserver:adsites:site?name=Test-AD" $search_results = Invoke-RestMethod -Uri $search_url -Method GET -WebSession $authcookie $ref = $search_results._ref $change_url = "https://$domain/wapi/v2.10/" + $ref +"?_function=move_subnets" $body = '{"networkcontainer":["10.1.2.0/24"]}' $change_results = Invoke-RestMethod -Uri $change_url -Method POST -ContentType 'application/json' -WebSession $authcookie -Body $body
I think there is an error on how I parse the array with the "networkcontainer" IP. Can sombody give me a hint on how to correctly input the Network Container IP?
Re: WAPI: Create Network Container with Active Directory Site assigned
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2022 05:56 PM - edited 06-27-2023 01:19 PM
Hello Julian,
Can you try this & see if it works ?
$body = '{"networkcontainer":[{"10.1.2.0/24"}]}'
Best regards,
Re: WAPI: Create Network Container with Active Directory Site assigned
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2022 10:00 PM
Hi Mohammed,
sadly still HTTP 400.
Re: WAPI: Create Network Container with Active Directory Site assigned
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2022 05:08 AM
it would be good to see what the error response is, with the 400 error.
Try replacing your last line, where the request is being made, with a try/catch section, to extract and display the error content returned with the http error response:
try {
$change_results = Invoke-RestMethod -Uri $change_url -Method POST -ContentType 'application/json' -WebSession $authcookie -Body $body
}
catch {
$result_stream = $change_results.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result_stream)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
$responseError = $responseBody | ConvertFrom-Json
$responseError.text
}
Re: WAPI: Create Network Container with Active Directory Site assigned
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2022 05:30 AM - edited 09-27-2022 05:30 AM
Hi, with
$body = '{"networkcontainer":["10.1.2.0/24"]}'
the Error is: AdmConProtoError: required function parameter missing: networks
With
$body = '{"networks":["10.1.2.0/24"]}'
the Error is: AdmConProtoError: Invalid reference: 10.1.2.0/24
10.1.2.0/24 is a container, but the function is requesting the parameter "networks" even though the WAPI documentation says it also accepts "networkcontainer" and in the GUI it is possible to assign an AD Site to a network container too. I am very puzzled.