KaceSMA
KaceSMA copied to clipboard
Creating barcodes with assets
Having issues creating a new asset and a barcode with it. From the documentation barcodeData schema, it looks like the monitor asset has to be created before the barcode can be created:
asset_id required: Only valid when creating new barcode. Required, used to associate with a specific asset
If that's correct, it looks like we'll need another cmdlet like New-SmaAssetBarcode
to follow up with. I've tried to use the New-SmaAsset
cmdlet but a body for a barcode, shown below, and it does return successful, but I don't see any changes reflected in KACE.
Input:
> # Create monitor asset in KACE
$Monitors.$hostname.Keys | select -first 1 | ForEach-Object {
$mon = $Monitors.$hostname.$_
$NewAsset = @{
'Assets' = @(
@{
'name' = '{0} {1}' -f $mon.ModelNumber, $owner
'asset_type_id' = '10201'
'asset_type_name' = 'Monitors'
'field_10027' = $mon.SerialNumber
'field_10033' = $mon.ManufactureDate
'field_10026' = @{
'id' = $kaceComputer.id
'asset_type_id' = 5
}
}
)
}
$asset = New-SmaAsset -Body $NewAsset
if ($asset.result -eq 'Success') {
'- Asset created in KACE. Asset ID: {0} Link: https://K1000/adminui/asset.php?ID={0}' -f $asset.IDs
} else {
'- Asset creation failed.'
}
# Barcodes
$barcodeData = $mon.SerialNumber.Replace('-', '')[-7..-1] -join ''
$newBarcode = @{
'barcodes' = @(
@{
'barcode_id' = $asset.IDs
'barcode_data' = $barcodeData
'barcode_name' = 'Monitor Serial Number'
'barcode_format' = 'Code 128'
'scanned_geolocation' = 'UNKNOWN'
'scanned_method' = 'UNKNOWN'
}
)
}
'- creating barcode'
$barcode = New-SmaAsset -Body $newBarcode
$barcode; ''
}
Output:
- Asset created in KACE. Asset ID: 919 Link: https://K1000/adminui/asset.php?ID=919
- creating barcode
Result IDs
------ ---
Success {}
>
Thanks
Alex