This is the function that calls the API, encase it's needed, but like I said it different assets serials that error, and some times when the script it ran, it doesn't error at all, but usually it errors once or twice a run.
Function GetComputerBySerial {
param ([Parameter(Mandatory=$true)]$serial)
$assetDevice = $null
# Build XMLMC API call
# params have to be in the expected order.
$filter = '[{"column_name":"h_serial_number","column_value":"'+$serial+'","operator":"Equals","isGeneralProperty":false}]'
Clear-Params
Add-Param "resultType" "data"
Add-Param "assetClass" "computer"
Add-Param "filters" $filter
# Invoke XMLMC call, output returned as PSObject
$xmlmcOutput = Invoke-XMLMC "apps/com.hornbill.servicemanager/Asset" "getAssetsFiltered"
$jsonData = ConvertTo-Json -InputObject $xmlmcOutput
# Read output status
if($xmlmcOutput.status -eq "ok") {
# Data return is corrects
if ($null -ne $xmlmcOutput.params.data)
{
$assetDevice = (ConvertFrom-Json $xmlmcOutput.params.data)[0]
}
else
{
return $false
}
} else {
# API call status not OK - return status and error to console
WriteOut "API Call Status : $($xmlmcOutput.status)"
WriteOut "Error Returned : $($xmlmcOutput.error)"
WriteOut "Error as JSON : $($jsonData)"
}
return $assetDevice
}