I'm trying to copy Horizon application pools that exist on a source Horizon connection server (HCS) to another one. In my homelab that works perfectly, in another environment on "invoke-restmethod" I run into the error above.
First I get an auth token and the applications on the source HCS:
$horizonApps_source = Invoke-RestMethod -Method Get -uri "$RESTurl_source/rest/inventory/v2/application-pools" -ContentType "application/json" -Headers (Get-HRHeader -accessToken $accessToken_source)`
Then I loop through them and create the copies on the target HCS (also exporting a .json-File for every app and removing unique values that the POST "inventory/v2/application-pools" will not accept):
If ($horizonApps_source -ne $null) {
ForEach ($item in $horizonApps_source) {
$jsonFile = $fileLoc + $item.Display_Name + ".json"
$item = $item | Select-Object * -ExcludeProperty Id, access_group_id, icon_ids, customized_icon_ids
$item.farm_id = $farmID_target
$item | ConvertTo-Json -Depth 100 | Out-File $jsonFile
$appJson = $item | ConvertTo-Json -Depth 100
$app_target = Invoke-RestMethod -Method Post -uri "$RESTurl_target/rest/inventory/v2/application-pools" -ContentType "application/json" -Headers (Get-HRHeader -accessToken $accessToken_target) -body $appJson -SkipCertificateCheck
}
}
In one environment everything works, in another no chance...this is the error I get, .json-files are written and look okay, but no apps are created on the target HCS:
Line |
8 | … pp_target = Invoke-RestMethod -Method Post -uri "$RESTurl_target/rest …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| {"status":"BAD_REQUEST","timestamp":1670869477302,"error_message":"The input request cannot be parsed."}
Powershell 7.3.0, PowerCLI 13, Horizon 2111 everywhere. Any ideas? Any suggestion how I could catch the error in more detail to find the issue's source?
Tried to google problems with invoke-restmethod using a json-body. Sadly I'm not a Powershell pro...