Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stephecannon opened this issue Mar 5, 2023 · 1 comment

Comments

@stephecannon
Copy link

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

  • SnipitPS Module version used: 1.10.227
  • Operating System and PowerShell version: Windows 11 / Powershell 7.3.2
  • Snipe It version: v6.0.10

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
Copy link
Author

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.

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

No branches or pull requests

1 participant