Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Assets from Powershell script fails when Attribute is an Object

Ste404
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2022

Hi there,

I am building a powershell script to update Assets from a CSV that will run as a scheduled task.  It works fine when the attribute types in the schema are not "Object"

Basically I am building a PSCustomObject using this

function Get-MappingData ($user) {
<#
.SYNOPSIS
This will map AD attributes to Insight fields.
#>
$mappings = [PSCustomObject]@{
Imp_Name = [PSCustomObject]@{name="Name"; id=199; value=$user.Name}
Imp_Model = [PSCustomObject]@{name="Model"; id=337; value=$user.Model}
Imp_Owner = [PSCustomObject]@{name="Owner"; id=339; value=$user.Owner}

}

return $mappings
}

When when you look at the output when I am displaying the mapping data it picks up the correct information;

 [2022-11-16 11:59:11] Updating IEA-721 LAP-22-APP-2344
[2022-11-16 11:59:11] ERROR setting object: {
"objectTypeId": 49,
"attributes": [
{
"objectTypeAttributeId": 199,
"objectAttributeValues": [
{
"value": "LAP-22-APP-2344"
}
]
},
{
"objectTypeAttributeId": 337,
"objectAttributeValues": [
{
"value": "MacBook Pro - 16 Space Gray"
}
]
},
{
"objectTypeAttributeId": 339,
"objectAttributeValues": [
{
"value": "Max Taylor"
}
]
}
]
}

 

But it fails to do anything due to Attribute 337 and 339 being Object.  I am not sure what to try and put here to somehow look up the other Schema where the People and Assets are stored to get the ID information that I am going to need for these value (I assume).

I need the Owner to be an Object as it needs to be able to bind through from the People schema to display associated assets in a ticket.

The CSV will be produced automatically from an assets system and this powershell import will happen automatically also.  If I dop the Attribute 337 and 339 the script works fine as Attribute 199 is just the 'Default' type so nothing to reference there and it all works fine.

So basically I am going to need to be able to look back in Insight and match the values in the CSV and pull out the key and then use that as the update.

Just not sure how to loop backwards into Assets for that part of it?


Any suggestions? 

2 answers

0 votes
Sergey Ageev January 25, 2023

@Ste404 you may need instead of using a String Value try to insert a Key Value for the associated object (something like KEY-1234), in my case it works.

0 votes
Sergey Ageev January 21, 2023

Wondering if you found a solution? I am facing a similar issue with binding the object.

 

Response Code: HTTP/1.1 400 Bad Request

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events