Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Creating barcodes with assets #32

Open
MrAlexFranco opened this issue Jun 5, 2020 · 0 comments
Open

Creating barcodes with assets #32

MrAlexFranco opened this issue Jun 5, 2020 · 0 comments

Comments

@MrAlexFranco
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant