snazy2000 / SnipeitPS

Powershell API Wrapper for Snipe-it
MIT License
181 stars 47 forks source link

Return MAC Address (custom fieldset) with "Get-SnipeITAsset -status 'Deployed'" #297

Open stephecannon opened 1 year ago

stephecannon commented 1 year ago

I am attempting to get all assets with a status of "Deployed" and return a custom field (MAC Address) with the result (to later be ingested by my Network Access Control system).

It appears that the "-customfields" flag wants a hashtable...?

I can understand the need for a hashtable in the set-snipeitasset command because you want to set the custom field to a value, but I am failing to understand how the command could be used to return the custom field value.

Is this an error or am I missing something?

Your Environment

Expected Behavior

I would expect to use the Get-SnipeITAsset command like this: get-snipeitasset -status 'Deployed' -cusomfields 'MAC Address'

Current Behavior

get-snipeitasset -status 'deployed' -customfields 'MAC Address' Get-SnipeitAsset: Cannot process argument transformation on parameter 'customfields'. Cannot convert the "MAC Address" value of type "System.String" to type "System.Collections.Hashtable".

Possible Solution

I'm good with formatting my custom field request as a hashtable, but as I am expecting to receive a variable I would expect the value to be empty.

Steps to Reproduce (for bugs)

  1. Open Powershell
  2. Have your url and api key established in your script
  3. In powershell "Import-Module SnipeitPS" then "Connect-SnipeitPS -URL 'https://YOUR.url' -apiKey $APIKey"
  4. Then in powershell "Get-SnipeitAsset -status "Ready to Deploy" -customfields 'MAC Address'''
stephecannon commented 1 year ago

I did find a route around. Turns out that the customfields were being obscured by the output in powershell of the values returned with the command "get-snipeitasset -status 'Ready to Deploy'"

# Get all equipment that is of status "Ready to Deploy" ...
$ValidDevices = get-snipeitasset -status 'Ready to Deploy'

#Parse the deployed devices for their wired MAC addresses
$ValidWiredMACAddresses = $ValidDevices.custom_fields.'MAC Address'.value

By dumping the output into a object ($ValidDevices) and then parsing that variable, then dumping those values into a new object ($ValidWiredMACAddresses) I was able to get what I wanted.

That said, this is a bit of an "out of the way" method of accomplishing my task assuming that the -customfields flag is there on purpose.