Set-Asset-Field reports success when it actually fails

This isn’t causing me a real problem, I just noticed it while doing some testing. If I attempt to write to a custom asset field that doesn’t exist, the result of set-asset-field is reported as a success. For example, if I do this:

set-asset-field -Name "NonExistentField" -Value "Test"

The reported result in Script Output is:

Call-SyncroApi: success

If I pass a bad value to a field that does exist I also get a success when I shouldn’t:

$SetResult = set-asset-field -Name "CrowdstrikeInstalled" -Value This should not work

This results in the script writing the value “This” to my custom field, and reports Call-SyncroApi: success. This script:

$data = @{

"key1" = "This"
"key2" = "Should"
"key3" = "Not"
"key4" = "Work"


set-asset-field -Name "CrowdstrikeInstalled" -Value $data

Results in the field looking like this, but is again reported as a success:


I haven’t tried it, but would

set-asset-field -Name "CrowdstrikeInstalled" -Value $data.Value

store the value instead of the data type?

“Success” would be the correct status from a scripting point of view.
The reason is that the Powershell contents of the variable $data in this row

set-asset-field -Name “CrowdstrikeInstalled” -Value $data

is a memory pointer to the hash table previously defined.
Powershell doesn’t ever provide the actual memory location, and instead displays “System.Collections.HashTable” to the set-asset-field command.

$data = @{ }

is the syntax to create a hashtable of N key value pairs.
The value of each key could also be further data hashtables.
Therefore if you only refer to $data, you are refering to the entire hashtable, not any single key value pair.

1 Like

I’m less concerned about actually being able to store this type of data than I am with the function claiming success when it fails. I don’t actually have a use case for a hash table, so that’s on me. I was just looking for different failure points to test.

What I’m concerned about is getting accurate reports from the function so I can better read the output of my scripts.