homotechsual / HaloAPI

PowerShell module for the Halo Service Solutions series of software products.
MIT License
47 stars 35 forks source link

[Question]: Search for Clients who have a custom object #14

Closed E1iTeDa357 closed 1 year ago

E1iTeDa357 commented 1 year ago

Contact Details

No response

What happened?

Was wondering if you can query all clients and only return clients that have a custom field of a certain value?

Version

1.0.1

Which operating systems have you tested on?

What PowerShell version are you running?

7.0.6

Halo Product

Halo PSA

Halo Version

2.88.21

What command did you run?

No response

What was the output of the command?

No response

homotechsual commented 1 year ago

Good question, and an example I'll make a note to add when I get to this cmdlet.

Halo does not, natively, allow us to pre-filter results based on custom fields - the API doesn't support it. PowerShell however does.

Get-HaloClients -FullObjects | Where-Object { ($_.customfields.length -gt 0) -and ($_.customfields.name -eq 'CFCustomerTest' -and $_.customfields.value -eq 'Test') }

Change out CFCustomerTest with your chosen field name and Test with your required value.

E1iTeDa357 commented 1 year ago

Can you also give an example of: 1. how to update a CF at the client level. And also how to update/add a subscription and quanity for a client? Really appreciate the help!

homotechsual commented 1 year ago
  1. Custom Fields:
    $CustomFields = (Get-HaloClient -ClientId 17).CustomFields # When updating custom fields we have to get the current values - we can't just "blindly" set the value without wiping out any other custom field values.
    ForEach ($CustomField in $CustomFields | Where-Object { $_.name -eq 'CFCustomerTest' }) { $CustomField.Value = 'TestTest' } 
    Set-HaloClient -Client @{ id = 17; customfields = $CustomFields }

For subscriptions/quantities - I would strongly recommend relying on the CSP, Azure AD or other integrations if you can.

E1iTeDa357 commented 1 year ago

For subscriptions/quantities - I would strongly recommend relying on the CSP, Azure AD or other integrations if you can. Yes for Microsoft licenses the CSP intergration works well but if we want to have ALL of the other products that we sell as an MSP updated automatically for billing the best way I found was to tie an invoice line item to a subscription quantity so when we sell things like backup licenses, antivirus licenses etc. I think that's the best place to have those counts correct? We have found the endpoint /api/SoftwareLicenses that works for us.