I'm working with our Help Desk Service's API using PowerShell, and I want to streamline the process of pulling information from New Hire Tickets to reduce manual errors when creating accounts. When I call up the details of a ticket, I get a single-line output formatted like this: @{first_name=Value; middle_name_not_required=; last_name=' title; ...}.
I need to access specific values from this output, such as getting the first name with something like $customVariable.first_name, but I'm struggling because it seems to be a custom object rather than a straightforward string. I've tried storing the ticket details in a variable ($custom) and using the Split method, but I'm hitting an error that says the object doesn't support that method. Can anyone help me figure out how to access these values correctly?
3 Answers
If you think it looks like JSON, you might want to try `ConvertFrom-JSON` on your API result. It would help parse the output into a more manageable format if it's actually JSON. This way, you can easily access the properties as you would with plain PowerShell objects.
It looks like the output is not a string but rather a custom object! You should access the properties directly. For your case, try `$custom.custom_fields.first_name` to get the first name value. Since it's structured as an object, there's no need to split it – just call the property directly and retrieve the values you need.
If you're seeing the output as `@{first_name=Value; ...}`, that's a PSCustomObject which you can access the properties from directly. Instead of trying to split the string, check the type with `$custom.custom_fields.GetType()` to confirm it's an object, then you can use `$custom.custom_fields.first_name` to get the specific values you want.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically