I'm using the REST API via Powershell to add a description to computers. For some systems this fails with the error "The requested hostname already exists." It works for systems where the computer exists once in TM but not if the system exists twice.
This is in DSaaS.
Here is the powershell script part with the rest calls in it. The same call works for a server with a unique name in DS but not for servers which exist multiple times
{
$srv = $_.Name
$ci = $_.CI
$searchbody = @{
"searchCriteria"= @{
"fieldName" = "hostName"
"stringTest" = "equal"
"stringValue" = $srv+'%'}
}
$json = ConvertTo-Json $searchbody
$srvuri = "$url/computers/search?expand=none"
$computer = Invoke-RestMethod -Uri $srvuri -Method Post -Headers $headers -Body $json -ContentType 'application/json' -Proxy $proxy
$computer.computers | ForEach-Object {
$computerid = $_.ID
"{0} Setting CI $ci for Server $srv with ID {1}" -f (Get-Date -Format u),$computerid
$date = Get-Date -Format "yyyy-MM-dd"
$_.description+= "`n$($date): $ci"
$updatejson = ConvertTo-Json $_
$updateuri="$url/computers/$computerid"
$computerupdate = Invoke-RestMethod -Uri $updateuri -Method Post -Headers $headers -Body $updatejson -ContentType 'application/json' -Proxy $proxy
}
}
Any explanation what mistake I make here is highly apreciated.